Drivers: hv: Implement the file copy service
PATCH v4 1/1 Drivers: hv: Implement the file copy service
Implement the file copy service for Linux guests on Hyper-V. This permits the host to copy a file (over VMBUS) into the guest. This facility is part of "guest integration services" supported on the Windows platform. Here is a link that provides additional details on this functionality:
http://technet.microsoft.com/en-us/library/dn464282.aspx
In V1 version of the patch I have addressed comments from Olaf Hering <[email protected]> and Dan Carpenter <[email protected]>
In V2 version of this patch I did some minor cleanup (making some globals static). In V4 version of the patch I have addressed all of Olaf's most recent set of comments/concerns.
--- drivers/hv/Makefile | 2 +- drivers/hv/hv_fcopy.c | 428 ++++++++++++++++++++++++++++++++++++++++++++ drivers/hv/hv_util.c | 10 + include/linux/hyperv.h | 61 +++++++ tools/hv/hv_fcopy_daemon.c | 200 +++++++++++++++++++++ 5 files changed, 700 insertions(+), 1 deletions(-) create mode 100644 drivers/hv/hv_fcopy.c create mode 100644 tools/hv/hv_fcopy_daemon.c
drivers/hv/Makefile +1 -1
@@ -5,4 +5,4 @@ obj-$(CONFIG_HYPERV_BALLOON) += hv_balloon.o hv_vmbus-y := vmbus_drv.o \ hv.o connection.o channel.o \ channel_mgmt.o ring_buffer.o -hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o +hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_fcopy.o
drivers/hv/hv_fcopy.c new file +428 -0
428 lines not on this page · raw message
drivers/hv/hv_util.c +10 -0
@@ -82,6 +82,12 @@ static struct hv_util_service util_vss = { .util_deinit = hv_vss_deinit, }; +static struct hv_util_service util_fcopy = { + .util_cb = hv_fcopy_onchannelcallback, + .util_init = hv_fcopy_init, + .util_deinit = hv_fcopy_deinit, +}; +static void perform_shutdown (struct work_struct *dummy) {orderly_poweroff (true);
@@ -401,6 +407,10 @@ static const struct hv_vmbus_device_id id_table[] = { { HV_VSS_GUID, .driver_data = (unsigned long )&util_vss }, + /* File copy GUID */ + { HV_FCOPY_GUID, + .driver_data = (unsigned long )&util_fcopy + }, { }, };
include/linux/hyperv.h +61 -0
85 lines not on this page · raw message
tools/hv/hv_fcopy_daemon.c new file +200 -0
200 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Quoted 4 lines · K. Y. Srinivasan
Implement the file copy service for Linux guests on Hyper-V. This permits the host to copy a file (over VMBUS) into the guest. This facility is part of "guest integration services" supported on the Windows platform. Here is a link that provides additional details on this functionality:
Looks ok to me now. Thanks.
include/linux/hyperv.h line 29
Quoted 6 lines
+++
b/include/linux/hyperv.hinclude/linux/hyperv.h +1
-0@@ -26,6 +26,7 @@#define _HYPERV_H#include <linux/types.h> +#include <linux/uuid.h>
uuid.h is also include in the __KERNEL__ section later in the file.
Olaf
drivers/hv/hv_fcopy.c line 260
Quoted 7 lines · K. Y. Srinivasan
drivers/hv/hv_fcopy.c new file +7
-0+/* +* Create a char device that can support read/write for passing +* the payload. +*/ +static struct cdev fcopy_cdev; +static struct class *cl; +static struct device *sysfs_dev;
Why not just be a misc device, you only want 1 minor number for a char device:
drivers/hv/hv_fcopy.c line 354
Quoted 5 lines
drivers/hv/hv_fcopy.c new file +5
-0+static int fcopy_dev_init (void ) +{ +int result; + + result =alloc_chrdev_region (&fcopy_dev,1 ,1 ,"hv_fcopy" );
See, one minor.
drivers/hv/hv_fcopy.c line 360
Quoted 6 lines
drivers/hv/hv_fcopy.c new file +6
-0+if (result <0 ) { +pr_err ("Cannot get major number\n" ); +return result; + } + + cl =class_create (THIS_MODULE ,"chardev" );
That's a _really_ generic name, come on, you know better than that.
drivers/hv/hv_fcopy.c line 362
Quoted 2 lines
drivers/hv/hv_fcopy.c new file +2
-0+if (IS_ERR (cl)) { +pr_err ("Error creating fcopy class.\n" );
Your error string is wrong :(
drivers/hv/hv_fcopy.c line 367
Quoted 5 lines
drivers/hv/hv_fcopy.c new file +5
-0+ result =PTR_ERR (cl); + goto err_unregister; + } + + sysfs_dev =device_create (cl,NULL , fcopy_dev,"%s" ,"hv_fcopy" );
A device at the root of sysfs? No, you have a bus to hang devices off of, use that. What do you need this device for anyway?
drivers/hv/hv_fcopy.c line 378
Quoted 11 lines
drivers/hv/hv_fcopy.c new file +11
-0+if (IS_ERR (sysfs_dev)) { +pr_err ("Device creation failed\n" ); + result =PTR_ERR (cl); + goto err_destroy_class; + } + +cdev_init (&fcopy_cdev, &fcopy_fops); + fcopy_cdev.owner =THIS_MODULE ; + fcopy_cdev.ops = &fcopy_fops; + + result =cdev_add (&fcopy_cdev, fcopy_dev,1 );
Ah, to get udev to pay attention to the char device, no, just use a misc device, should make this whole code a lot simpler and more "obvious" as to what you want/need.
drivers/hv/hv_fcopy.c line 391
Quoted 13 lines
drivers/hv/hv_fcopy.c new file +13
-0+if (result) { +pr_err ("Cannot cdev_add\n" ); + goto err_destroy_device; + } +return result; + +err_destroy_device: +device_destroy (cl, fcopy_dev); +err_destroy_class: +class_destroy (cl); +err_unregister: +unregister_chrdev_region (fcopy_dev,1 ); +return result;
Ugh, I hate the cdev interface, one of these days I'll fix it up, it's so unwieldy...
drivers/hv/hv_fcopy.c line 400
Quoted 7 lines
drivers/hv/hv_fcopy.c new file +7
-0+static void fcopy_dev_deinit (void ) +{ +/* +* first kill the daemon. +*/ +if (dtp !=NULL ) +send_sig (SIGKILL , dtp,0 );
We kill userspace daemon's from the kernel? That's a recipe for disaster...
Why? What does it matter here if the daemon keeps running, it should fail gracefully if the character device is removed, right? If not, that needs to be fixed anyway.
thanks,
greg k-h
Quoted 98 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Friday, February 07, 2014 3:17 PM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V4 1/1] Drivers: hv: Implement the file copy servicedrivers/hv/hv_fcopy.c line 260
Quoted 7 lines · K. Y. Srinivasan
drivers/hv/hv_fcopy.c new file +7
-0+/* +* Create a char device that can support read/write for passing +* the payload. +*/ +static struct cdev fcopy_cdev; +static struct class *cl; +static struct device *sysfs_dev;Why not just be a misc device, you only want 1 minor number for a char device:
drivers/hv/hv_fcopy.c line 354
Quoted 5 lines
drivers/hv/hv_fcopy.c new file +5
-0+static int fcopy_dev_init (void ) +{ +int result; + + result =alloc_chrdev_region (&fcopy_dev,1 ,1 ,"hv_fcopy" );See, one minor.
drivers/hv/hv_fcopy.c line 360
Quoted 6 lines
drivers/hv/hv_fcopy.c new file +6
-0+if (result <0 ) { +pr_err ("Cannot get major number\n" ); +return result; + } + + cl =class_create (THIS_MODULE ,"chardev" );That's a _really_ generic name, come on, you know better than that.
drivers/hv/hv_fcopy.c line 362
Quoted 2 lines
drivers/hv/hv_fcopy.c new file +2
-0+if (IS_ERR (cl)) { +pr_err ("Error creating fcopy class.\n" );Your error string is wrong :(
drivers/hv/hv_fcopy.c line 367
Quoted 5 lines
drivers/hv/hv_fcopy.c new file +5
-0+ result =PTR_ERR (cl); + goto err_unregister; + } + + sysfs_dev =device_create (cl,NULL , fcopy_dev,"%s" ,"hv_fcopy" );A device at the root of sysfs? No, you have a bus to hang devices off of, use that. What do you need this device for anyway?
drivers/hv/hv_fcopy.c line 378
Quoted 11 lines
drivers/hv/hv_fcopy.c new file +11
-0+if (IS_ERR (sysfs_dev)) { +pr_err ("Device creation failed\n" ); + result =PTR_ERR (cl); + goto err_destroy_class; + } + +cdev_init (&fcopy_cdev, &fcopy_fops); + fcopy_cdev.owner =THIS_MODULE ; + fcopy_cdev.ops = &fcopy_fops; + + result =cdev_add (&fcopy_cdev, fcopy_dev,1 );Ah, to get udev to pay attention to the char device, no, just use a misc device, should make this whole code a lot simpler and more "obvious" as to what you want/need.
drivers/hv/hv_fcopy.c line 391
Quoted 13 lines
drivers/hv/hv_fcopy.c new file +13
-0+if (result) { +pr_err ("Cannot cdev_add\n" ); + goto err_destroy_device; + } +return result; + +err_destroy_device: +device_destroy (cl, fcopy_dev); +err_destroy_class: +class_destroy (cl); +err_unregister: +unregister_chrdev_region (fcopy_dev,1 ); +return result;Ugh, I hate the cdev interface, one of these days I'll fix it up, it's so unwieldy...
drivers/hv/hv_fcopy.c line 400
Quoted 7 lines
drivers/hv/hv_fcopy.c new file +7
-0+static void fcopy_dev_deinit (void ) +{ +/* +* first kill the daemon. +*/ +if (dtp !=NULL ) +send_sig (SIGKILL , dtp,0 );We kill userspace daemon's from the kernel? That's a recipe for disaster...
Quoted 3 lines
Why? What does it matter here if the daemon keeps running, it should fail gracefully if the character device is removed, right? If not, that needs to be fixed anyway.
Greg,
Thanks for the detailed comments; I will address these in the next version.
Regards,
K. Y