Drivers: hv: Implement the file copy service
PATCH v3 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 this 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 | 423 ++++++++++++++++++++++++++++++++++++++++++++ drivers/hv/hv_util.c | 10 + include/linux/hyperv.h | 60 +++++++ tools/hv/hv_fcopy_daemon.c | 194 ++++++++++++++++++++ 5 files changed, 688 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 +423 -0
423 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 +60 -0
84 lines not on this page · raw message
tools/hv/hv_fcopy_daemon.c new file +194 -0
194 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Hello,
Quoted 10 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:
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]>
Quoted 6 lines
In V2 version of this patch I did some minor cleanup (making some globals static). In this version of the patch I have addressed all of Olaf's most recent set of comments/concerns.
Signed-off-by K. Y. Srinivasan <[email protected]>---
Just a few comments.
drivers/hv/hv_fcopy.c line 117
Quoted 8 lines
drivers/hv/hv_fcopy.c new file +8
-0+/* +* The strings sent from the host are encoded in +* in utf16; convert it to utf8 strings. +* The host assures us that the utf16 strings will not exceed +* the max lengths specified. We will however, reserve room +* for the string terminating character - in the utf16s_utf8s() +* function we limit the size of the buffer where the converted +* string is placed to W_MAX_PATH -1 to gaurantee
s/gaurantee/guarantee
Quoted 33 lines
drivers/hv/hv_fcopy.c new file +32
-0+* that the strings can be properly terminated! +*/ + +switch (operation) { +case START_FILE_COPY : +memset (smsg_out,0 ,sizeof (struct hv_start_fcopy )); + smsg_out->hdr.operation = operation; + smsg_in = (struct hv_start_fcopy *)fcopy_transaction.fcopy_msg; + +utf16s_to_utf8s ((wchar_t *)smsg_in->file_name,W_MAX_PATH , +UTF16_LITTLE_ENDIAN , + (__u8 *)smsg_out->file_name,W_MAX_PATH -1 ); + +utf16s_to_utf8s ((wchar_t *)smsg_in->path_name,W_MAX_PATH , +UTF16_LITTLE_ENDIAN , + (__u8 *)smsg_out->path_name,W_MAX_PATH -1 ); + + smsg_out->copy_flags = smsg_in->copy_flags; + smsg_out->file_size = smsg_in->file_size; +break ; + +default : +break ; + } +up (&fcopy_transaction.read_sema); +return ; +} + +static ssize_t fcopy_read (struct file *file,char __user *buf, +size_t count,loff_t *ppos) +{ +int ret;
drivers/hv/hv_fcopy.c
Quoted 10 lines
drivers/hv/hv_fcopy.c new file +10
-0+void *src; +size_t copy_size; +int operation; + +/* +* Wait until there is something to be read. +*/ + ret =down_interruptible (&fcopy_transaction.read_sema); +if (ret) +return -EINTR ;
I don't know, but since you use 'ret' only once and you don't even read it after, you could just simply remove it and check the return code of down_interruptible() directly
Quoted 6 lines
drivers/hv/hv_fcopy.c new file +6
-0+ + operation = fcopy_transaction.fcopy_msg->operation; + +if (operation ==START_FILE_COPY ) { + src = &fcopy_transaction.message; + copy_size =sizeof (struct hv_start_fcopy );
drivers/hv/hv_fcopy.c line 282
Quoted 10 lines
drivers/hv/hv_fcopy.c new file +10
-0+if (count < copy_size) +return 0 ; + }else { + src = fcopy_transaction.fcopy_msg; + copy_size =sizeof (struct hv_do_fcopy ); +if (count < copy_size) +return 0 ; + } +if (copy_to_user (buf, src, copy_size)) +return -EFAULT ;
...like you do here.
Signature · 2 lines
Regards, Levente Kurusa
Quoted 34 lines
-----Original Message-----
From: Levente Kurusa [mailto:[email protected]] On Behalf Of Levente Kurusa
Sent: Tuesday, January 21, 2014 11:01 AM
To: KY Srinivasan; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V3 1/1] Drivers: hv: Implement the file copy serviceHello,
Quoted 9 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:
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
Quoted 7 lines
In V2 version of this patch I did some minor cleanup (making some globals static). In this version of the patch I have addressed all of Olaf's most recent set of comments/concerns.
Signed-off-by K. Y. Srinivasan <[email protected]>---
Just a few comments.
Quoted 10 lines
drivers/hv/hv_fcopy.c line 117
Quoted 8 lines
drivers/hv/hv_fcopy.c new file +8
-0+/* +* The strings sent from the host are encoded in +* in utf16; convert it to utf8 strings. +* The host assures us that the utf16 strings will not exceed +* the max lengths specified. We will however, reserve room +* for the string terminating character - in the utf16s_utf8s() +* function we limit the size of the buffer where the converted +* string is placed to W_MAX_PATH -1 to gaurantee s/gaurantee/guarantee
I will fix this.
Quoted 45 lines
drivers/hv/hv_fcopy.c
Quoted 9 lines
drivers/hv/hv_fcopy.c new file +8
-0+* that the strings can be properly terminated! +*/ + +switch (operation) { +case START_FILE_COPY : +memset (smsg_out,0 ,sizeof (struct hv_start_fcopy )); + smsg_out->hdr.operation = operation; + smsg_in = (struct hv_start_fcopy*)fcopy_transaction.fcopy_msg;
Review
Quoted 2 lines
(quoted diff) +2
-0+ + utf16s_to_utf8s((wchar_t *)smsg_in->file_name,
W_MAX_PATH,Review
Quoted 2 lines
(quoted diff) +2
-0+ UTF16_LITTLE_ENDIAN, + (__u8 *)smsg_out->file_name, W_MAX_PATH -1);
Review
Quoted 2 lines
(quoted diff) +2
-0+ + utf16s_to_utf8s((wchar_t *)smsg_in->path_name,
W_MAX_PATH,Review
Quoted 2 lines
(quoted diff) +2
-0+ UTF16_LITTLE_ENDIAN, + (__u8 *)smsg_out->path_name, W_MAX_PATH -1);
Quoted 23 lines
drivers/hv/hv_fcopy.c new file +22
-0+ + smsg_out->copy_flags = smsg_in->copy_flags; + smsg_out->file_size = smsg_in->file_size; +break ; + +default : +break ; + } +up (&fcopy_transaction.read_sema); +return ; +} + +static ssize_t fcopy_read (struct file *file,char __user *buf, +size_t count,loff_t *ppos) +{ +int ret; +void *src; +size_t copy_size; +int operation; + +/* +* Wait until there is something to be read.
Quoted 8 lines
drivers/hv/hv_fcopy.c line 266
Quoted 4 lines
drivers/hv/hv_fcopy.c new file +4
-0+*/ + ret =down_interruptible (&fcopy_transaction.read_sema); +if (ret) +return -EINTR ;I don't know, but since you use 'ret' only once and you don't even read it after, you could just simply remove it and check the return code of
down_interruptible()directly
Good point; I will fix this.
Thank you,
K. Y
On Tue, Jan 21, K. Y. Srinivasan wrote:
Looks better. A few comments below:
Quoted 3 lines
+++
b/drivers/hv/hv_fcopy.c+static bool
daemon_died;
This is a write only variable.
Quoted 1 line
+static u32
daemon_version;
This is a write only variable.
drivers/hv/hv_fcopy.c line 97
Quoted 6 lines
drivers/hv/hv_fcopy.c new file +6
-0+static int fcopy_handle_handshake (u32 version) +{ +pr_info ("FCP: user-mode registering done. Daemon version: %d\n" , + version); + fcopy_transaction.active = false; + daemon_version = version;
I think fcopy_handle_handshake should proactivly reject requests if version is not 0.
There is an unused FCOPY_VERSION as well. I think this should not be in a header. Instead the kernel should handle all known versions and reject everything it does not know about.
tools/hv/hv_fcopy_daemon.c line 49
Quoted 1 line
tools/hv/hv_fcopy_daemon.c new file +1
-0+syslog (LOG_INFO ,"Target file name: %s\n" , target_fname);
Newline in syslog
tools/hv/hv_fcopy_daemon.c line 63
Quoted 2 lines
tools/hv/hv_fcopy_daemon.c new file +2
-0+if (mkdir ((char *)smsg->path_name,0755 )) { + syslog(LOG_ERR, "Failed to create %s\n",
Newline in syslog
tools/hv/hv_fcopy_daemon.c line 78
Quoted 1 line
tools/hv/hv_fcopy_daemon.c new file +1
-0+syslog (LOG_INFO ,"File: %s exists\n" , target_fname);
Newline in syslog
tools/hv/hv_fcopy_daemon.c line 85
Quoted 1 line
tools/hv/hv_fcopy_daemon.c new file +1
-0+syslog (LOG_INFO ,"Open Failed: %s\n" ,strerror (errno));
Newline in syslog
tools/hv/hv_fcopy_daemon.c line 161
Quoted 1 line
tools/hv/hv_fcopy_daemon.c new file +1
-0+ syslog(LOG_ERR, "Read error: %s\n",
Newline in syslog
tools/hv/hv_fcopy_daemon.c line 184
Quoted 1 line
tools/hv/hv_fcopy_daemon.c new file +1
-0+ syslog(LOG_ERR, "Unknown operation: %d\n",
Newline in syslog
Olaf