Skip to contentSkip to conversation

scsi: storvsc: Add the support of hibernation

PATCH Applied Dexuan Cui 4 participants 5 messages Sep 11, 2019 – Oct 1, 2019

Subsystems (3)
lore
Share & tools
lore

Dexuan Cui

author maintainer
#0 lore raw

PATCH 1/1 scsi: storvsc: Add the support of hibernation

When we're in storvsc_suspend(), we're sure the SCSI layer has quiesced the scsi device by scsi_bus_suspend() -> ... -> scsi_device_quiesce(), so the low level SCSI adapter driver only needs to suspend/resume its own state.

---

This patch is basically a pure Hyper-V specific change and it has a build dependency on the commit 271b2224d42f ("Drivers: hv: vmbus: Implement suspend/resume for VSC drivers for hibernation"), which is on Sasha Levin's Hyper-V tree's hyperv-next branch:
https://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git/log/?h=hyperv-next

I request this patch should go through Sasha's tree rather than the SCSI tree.

 drivers/scsi/storvsc_drv.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
drivers/scsi/storvsc_drv.c +41 -0
index ed8b9ac..9fbf604 100644
@@ -1727,6 +1727,13 @@ enum {
 
 MODULE_DEVICE_TABLE(vmbus, id_table);
 
+static const struct { guid_t guid; } fc_guid = { HV_SYNTHFC_GUID };
+
+static bool hv_dev_is_fc(struct hv_device *hv_dev)
+{
+	return guid_equal(&fc_guid.guid, &hv_dev->dev_type);
+}
+
 static int storvsc_probe(struct hv_device *device,
 			const struct hv_vmbus_device_id *dev_id)
 {
@@ -1935,11 +1942,45 @@ static int storvsc_remove(struct hv_device *dev)
 	return 0;
 }
 
+static int storvsc_suspend(struct hv_device *hv_dev)
+{
+	struct storvsc_device *stor_device = hv_get_drvdata(hv_dev);
+	struct Scsi_Host *host = stor_device->host;
+	struct hv_host_device *host_dev = shost_priv(host);
+
+	storvsc_wait_to_drain(stor_device);
+
+	drain_workqueue(host_dev->handle_error_wq);
+
+	vmbus_close(hv_dev->channel);
+
+	memset(stor_device->stor_chns, 0,
+	       num_possible_cpus() * sizeof(void *));
+
+	kfree(stor_device->stor_chns);
+	stor_device->stor_chns = NULL;
+
+	cpumask_clear(&stor_device->alloced_cpus);
+
+	return 0;
+}
+
+static int storvsc_resume(struct hv_device *hv_dev)
+{
+	int ret;
+
+	ret = storvsc_connect_to_vsp(hv_dev, storvsc_ringbuffer_size,
+				     hv_dev_is_fc(hv_dev));
+	return ret;
+}
+
 static struct hv_driver storvsc_drv = {
 	.name = KBUILD_MODNAME,
 	.id_table = id_table,
 	.probe = storvsc_probe,
 	.remove = storvsc_remove,
+	.suspend = storvsc_suspend,
+	.resume = storvsc_resume,
 	.driver = {
 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
 	},
Signature · 1 line
1.8.3.1
#1 lore raw
Thank you for the patch! Yet something to improve:

Hi Dexuan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3-rc8 next-20190904]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Dexuan-Cui/scsi-storvsc-Add-the-support-of-hibernation/20190912-234223
config: i386-randconfig-b004-201936 (attached as .config)
compiler: gcc-7 (Debian 7.4.0-11) 7.4.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

>> drivers//scsi/storvsc_drv.c:1982:3: error: 'struct hv_driver' has no member named 'suspend'
     .suspend = storvsc_suspend,
      ^~~~~~~
>> drivers//scsi/storvsc_drv.c:1982:13: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
     .suspend = storvsc_suspend,
                ^~~~~~~~~~~~~~~
   drivers//scsi/storvsc_drv.c:1982:13: note: (near initialization for 'storvsc_drv.shutdown')
>> drivers//scsi/storvsc_drv.c:1983:3: error: 'struct hv_driver' has no member named 'resume'; did you mean 'remove'?
     .resume = storvsc_resume,
      ^~~~~~
      remove
>> drivers//scsi/storvsc_drv.c:1983:12: warning: excess elements in struct initializer

.resume = storvsc_resume,
^~~~~~~~~~~~~~
drivers//scsi/storvsc_drv.c:1983:12: note: (near initialization for 'storvsc_drv')
cc1: some warnings being treated as errors

vim +1982 drivers//scsi/storvsc_drv.c

1976
1977 static struct hv_driver storvsc_drv = {
1978 .name = KBUILD_MODNAME,
1979 .id_table = id_table,
1980 .probe = storvsc_probe,
1981 .remove = storvsc_remove,

> 1982		.suspend = storvsc_suspend,
> 1983		.resume = storvsc_resume,

1984 .driver = {
1985 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
1986 },
1987 };
1988

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

author maintainer
#2 lore raw
Quoted 21 lines

From: [email protected] <[email protected]> On Behalf Of kbuild test robot
Sent: Thursday, September 12, 2019 1:54 PM
To: Dexuan Cui <[email protected]>
Cc: [email protected]; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Michael Kelley <[email protected]>; Dexuan Cui <[email protected]>
Subject: Re: [PATCH] scsi: storvsc: Add the support of hibernation

Hi Dexuan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3-rc8 next-20190904]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

Quoted 4 lines
Quoted 1 line
Quoted 1 line

drivers//scsi/storvsc_drv.c:1982:3: error: 'struct hv_driver' has no member

named 'suspend'
.suspend = storvsc_suspend,
^~~~~~~

This build failure is expected: In the patch mail, I mentioned this patch has a build dependency on the commit 271b2224d42f ("Drivers: hv: vmbus: Implement suspend/resume for VSC drivers for hibernation"), which is on Sasha Levin's Hyper-V tree's hyperv-next branch:
https://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git/log/?h=hyperv-next

Thanks,
-- Dexuan

Acked-by on v1 1/1
#3 lore raw
In reply to Dexuan Cui

Dexuan,

Quoted 4 lines

When we're in storvsc_suspend(), we're sure the SCSI layer has quiesced the scsi device by scsi_bus_suspend() -> ... -> scsi_device_quiesce(), so the low level SCSI adapter driver only needs to suspend/resume its own state.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
Applied
#4 lore raw
Quoted 9 lines · Martin K. Petersen

Dexuan,

Quoted 4 lines

When we're in storvsc_suspend(), we're sure the SCSI layer has quiesced the scsi device by scsi_bus_suspend() -> ... -> scsi_device_quiesce(), so the low level SCSI adapter driver only needs to suspend/resume its own state.

Queued up for hyperv-next, thanks!

--
Thanks,
Sasha