From 32a88bbf9301d4d4fe84efdcd852b0af61365ec5 Mon Sep 17 00:00:00 2001 From: "K. Y. Srinivasan" Date: Tue, 10 May 2011 07:54:07 -0700 Subject: [PATCH] --- yaml --- r: 249463 b: refs/heads/master c: 604df37dc3ba185b1017f6ca5e497fbfb68da8d8 h: refs/heads/master i: 249461: 10bfb505e4d17f9c9cb2e4ffec0bb37a807b396b 249459: dd7f611df04b6206e3845233e7df1a2ee0079388 249455: e0f7e1536376303e2891398c0167828ad09ea25f v: v3 --- [refs] | 2 +- trunk/drivers/staging/hv/storvsc.c | 6 +++++- trunk/drivers/staging/hv/storvsc_api.h | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index 02355ca1a78a..072b61c777ce 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 43c51f7dd13c75962eebc4c28667d1b0162543ed +refs/heads/master: 604df37dc3ba185b1017f6ca5e497fbfb68da8d8 diff --git a/trunk/drivers/staging/hv/storvsc.c b/trunk/drivers/staging/hv/storvsc.c index 8ee1ad06e71b..36458b87f347 100644 --- a/trunk/drivers/staging/hv/storvsc.c +++ b/trunk/drivers/staging/hv/storvsc.c @@ -47,6 +47,7 @@ static inline struct storvsc_device *alloc_stor_device(struct hv_device *device) /* (ie get_stor_device() and must_get_stor_device()) to proceed. */ atomic_cmpxchg(&stor_device->ref_count, 0, 2); + init_waitqueue_head(&stor_device->waiting_to_drain); stor_device->device = device; device->ext = stor_device; @@ -332,7 +333,10 @@ static void stor_vsc_on_io_completion(struct hv_device *device, request->on_io_completion(request); - atomic_dec(&stor_device->num_outstanding_req); + if (atomic_dec_and_test(&stor_device->num_outstanding_req) && + stor_device->drain_notify) + wake_up(&stor_device->waiting_to_drain); + put_stor_device(device); } diff --git a/trunk/drivers/staging/hv/storvsc_api.h b/trunk/drivers/staging/hv/storvsc_api.h index 32228c067656..18879402eb01 100644 --- a/trunk/drivers/staging/hv/storvsc_api.h +++ b/trunk/drivers/staging/hv/storvsc_api.h @@ -26,6 +26,7 @@ #define _STORVSC_API_H_ #include +#include #include "vstorage.h" #include "vmbus_api.h" #include "vmbus.h" @@ -108,8 +109,11 @@ struct storvsc_device { /* 0 indicates the device is being destroyed */ atomic_t ref_count; + bool drain_notify; atomic_t num_outstanding_req; + wait_queue_head_t waiting_to_drain; + /* * Each unique Port/Path/Target represents 1 channel ie scsi * controller. In reality, the pathid, targetid is always 0 @@ -161,6 +165,14 @@ struct storvsc_driver *drv_to_stordrv(struct device_driver *d) return hvdr_to_stordr(hvdrv); } +static inline void storvsc_wait_to_drain(struct storvsc_device *dev) +{ + dev->drain_notify = true; + wait_event(dev->waiting_to_drain, + atomic_read(&dev->num_outstanding_req) == 0); + dev->drain_notify = false; +} + /* Interface */ int storvsc_dev_add(struct hv_device *device,