Drivers: hv: Add a new driver to support host initiated backup
PATCH 1/1 Drivers: hv: Add a new driver to support host initiated backup
This driver supports host initiated backup of the guest. On Windows guests, the host can generate application consistent backups using the Windows VSS framework. On Linux, we ensure that the backup will be file system consistent. This driver allows the host to initiate a "Freeze" operation on all the mounted file systems in the guest. Once the mounted file systems in the guest are frozen, the host snapshots the guest's file systems. Once this is done, the guest's file systems are "thawed".
This driver has a user-level component (daemon) that invokes the appropriate operation on all the mounted file systems in response to the requests from the host. The duration for which the guest is frozen is very short - a few seconds. During this interval, the diff disk is comitted.
--- drivers/hv/Makefile | 2 +- drivers/hv/hv_snapshot.c | 287 ++++++++++++++++++++++++++++++++++++++++ drivers/hv/hv_util.c | 10 ++ include/linux/hyperv.h | 69 ++++++++++ include/uapi/linux/connector.h | 5 +- tools/hv/hv_vss_daemon.c | 214 ++++++++++++++++++++++++++++++ 6 files changed, 585 insertions(+), 2 deletions(-) create mode 100644 drivers/hv/hv_snapshot.c create mode 100644 tools/hv/hv_vss_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_utils-y := hv_util.o hv_kvp.o hv_snapshot.o
drivers/hv/hv_snapshot.c new file +287 -0
287 lines not on this page · raw message
drivers/hv/hv_util.c +10 -0
@@ -49,6 +49,12 @@ static struct hv_util_service util_kvp = { .util_deinit = hv_kvp_deinit, }; +static struct hv_util_service util_vss = { + .util_cb = hv_vss_onchannelcallback, + .util_init = hv_vss_init, + .util_deinit = hv_vss_deinit, +}; +static void perform_shutdown (struct work_struct *dummy) {orderly_poweroff (true);
@@ -339,6 +345,10 @@ static const struct hv_vmbus_device_id id_table[] = { { HV_KVP_GUID, .driver_data = (unsigned long )&util_kvp }, + /* VSS GUID */ + { HV_VSS_GUID, + .driver_data = (unsigned long )&util_vss + }, { }, };
include/linux/hyperv.h +69 -0
87 lines not on this page · raw message
include/uapi/linux/connector.h +4 -1
@@ -44,8 +44,11 @@#define CN_VAL_DRBD 0x1#define CN_KVP_IDX 0x9/* HyperV KVP */ #define CN_KVP_VAL 0x1/* queries from the kernel */ +#define CN_VSS_IDX 0xA/* HyperV VSS */ +#define CN_VSS_VAL 0x1/* queries from the kernel */ -#define CN_NETLINK_USERS 10/* Highest index + 1 */ + +#define CN_NETLINK_USERS 11/* Highest index + 1 */ /* * Maximum connector's message size.
tools/hv/hv_vss_daemon.c new file +214 -0
214 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Quoted 10 lines · K. Y. Srinivasan
tools/hv/hv_vss_daemon.c new file +10
-0+static int vss_operate (int operation) +{ +char *fs_op; +char cmd[512 ]; +char buf[512 ]; +FILE *file; +char *p; +char *x; +int error; +
tools/hv/hv_vss_daemon.c line 61
Quoted 10 lines
tools/hv/hv_vss_daemon.c new file +10
-0+switch (operation) { +case VSS_OP_FREEZE : + fs_op ="-f " ; +break ; +case VSS_OP_THAW : + fs_op ="-u " ; +break ; + } + +sprintf (cmd,"%s" ,"mount | grep ^/dev/ | awk '{print $3 }'" );
I think this can be char cmd[] = "mount | awk '/^\/dev\/ { print $3'";
tools/hv/hv_vss_daemon.c line 75
Quoted 13 lines
tools/hv/hv_vss_daemon.c new file +13
-0+ file =popen (cmd,"r" ); +if (file ==NULL ) +return ; + +while ((p =fgets (buf,sizeof (buf), file)) !=NULL ) { + x =strchr (p,'\n' ); + *x ='\0' ; +if (!strncmp (p,"/" ,sizeof ("/" ))) +continue ; + +sprintf (cmd,"%s %s %s" ,"fsfreeze " , fs_op, p); +syslog (LOG_INFO ,"VSS cmd is %s\n" , cmd); + error =system (cmd);
error is not handled here, and it looks like only one error can be reported anyway.
In case of an error, will the host thaw the filesystems?
Quoted 9 lines
tools/hv/hv_vss_daemon.c new file +9
-0+ } +pclose (file); + +sprintf (cmd,"%s %s %s" ,"fsfreeze " , fs_op,"/" ); +syslog (LOG_INFO ,"VSS cmd is %s\n" , cmd); + error =system (cmd); + +return error; +}
Quoted 28 lines
-----Original Message-----
From: Olaf Hering [mailto:[email protected]]
Sent: Tuesday, March 12, 2013 2:49 PM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Evgeniy Polyakov
Subject: Re: [PATCH 1/1] Drivers: hv: Add a new driver to support host initiated backupQuoted 14 lines · K. Y. Srinivasan
tools/hv/hv_vss_daemon.c new file +14
-0+static int vss_operate (int operation) +{ +char *fs_op; +char cmd[512 ]; +char buf[512 ]; +FILE *file; +char *p; +char *x; +int error; + +switch (operation) { +case VSS_OP_FREEZE : + fs_op ="-f " ; +break ;
Quoted 8 lines
tools/hv/hv_vss_daemon.c line 61
Quoted 6 lines
tools/hv/hv_vss_daemon.c new file +6
-0+case VSS_OP_THAW : + fs_op ="-u " ; +break ; + } + +sprintf (cmd,"%s" ,"mount | grep ^/dev/ | awk '{print $3 }'" );I think this can be char cmd[] = "mount | awk '/^\/dev\/ { print $3'";
Yes; will make the change.
Quoted 10 lines
Quoted 10 lines
tools/hv/hv_vss_daemon.c new file +9
-0+ file =popen (cmd,"r" ); +if (file ==NULL ) +return ; + +while ((p =fgets (buf,sizeof (buf), file)) !=NULL ) { + x =strchr (p,'\n' ); + *x ='\0' ; +if (!strncmp (p,"/" ,sizeof ("/" ))) +continue ;
Quoted 8 lines
tools/hv/hv_vss_daemon.c line 75
Quoted 4 lines
tools/hv/hv_vss_daemon.c new file +4
-0+ +sprintf (cmd,"%s %s %s" ,"fsfreeze " , fs_op, p); +syslog (LOG_INFO ,"VSS cmd is %s\n" , cmd); + error =system (cmd);error is not handled here, and it looks like only one error can be reported anyway.
In case of an error, will the host thaw the filesystems?
Both freeze and thaw operations will not fail if properly applied. The only time the freeze operation fails is when there is already an active freeze in force. Likewise, the only time thaw fails is when there has not been a preceding freeze operation. So these errors will occur only when the VM user happens to be applying freeze/thaw operations independent of the host. In this case, the host simply reports an error on the host on the backup operation and nothing else is done.
Regards,
K. Y
Quoted 12 lines
tools/hv/hv_vss_daemon.c line 84
Quoted 10 lines
tools/hv/hv_vss_daemon.c new file +9
-0+ } +pclose (file); + +sprintf (cmd,"%s %s %s" ,"fsfreeze " , fs_op,"/" ); +syslog (LOG_INFO ,"VSS cmd is %s\n" , cmd); + error =system (cmd); + +return error; +}
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Quoted 16 lines · Olaf Hering
Quoted 14 lines · K. Y. Srinivasan
tools/hv/hv_vss_daemon.c new file +14
-0+static int vss_operate (int operation) +{ +char *fs_op; +char cmd[512 ]; +char buf[512 ]; +FILE *file; +char *p; +char *x; +int error; + +switch (operation) { +case VSS_OP_FREEZE : + fs_op ="-f " ; +break ;
Quoted 8 lines
tools/hv/hv_vss_daemon.c line 61
Quoted 6 lines
tools/hv/hv_vss_daemon.c new file +6
-0+case VSS_OP_THAW : + fs_op ="-u " ; +break ; + } + +sprintf (cmd,"%s" ,"mount | grep ^/dev/ | awk '{print $3 }'" );I think this can be char cmd[] = "mount | awk '/^\/dev\/ { print $3'";
After thinking about this part, perhaps start a helper script which has to provide as output the list of the mounted filesystems?
Olaf