aboutsummaryrefslogtreecommitdiffstats
path: root/tools/hv
diff options
context:
space:
mode:
authorOlaf Hering <olaf@aepfle.de>2013-04-24 10:48:52 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-04-24 12:02:35 -0400
commit7b413b65531422cc3d12a8acf53a43bc0d3c9f7b (patch)
treef9511bbf7630eda5c7c59b9f3994e5863ed16680 /tools/hv
parentd3d1ee3ab28711360937839423158cc185f710f2 (diff)
tools: hv: use FIFREEZE/FITHAW in hv_vss_daemon
As suggested by Paolo Bonzini, use ioctl instead of calling fsfreeze. Signed-off-by: Olaf Hering <olaf@aepfle.de> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/hv')
-rw-r--r--tools/hv/hv_vss_daemon.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c
index a5da91df4f76..dc73a897d8c6 100644
--- a/tools/hv/hv_vss_daemon.c
+++ b/tools/hv/hv_vss_daemon.c
@@ -21,7 +21,9 @@
21#include <sys/types.h> 21#include <sys/types.h>
22#include <sys/socket.h> 22#include <sys/socket.h>
23#include <sys/poll.h> 23#include <sys/poll.h>
24#include <sys/ioctl.h>
24#include <linux/types.h> 25#include <linux/types.h>
26#include <fcntl.h>
25#include <stdio.h> 27#include <stdio.h>
26#include <mntent.h> 28#include <mntent.h>
27#include <stdlib.h> 29#include <stdlib.h>
@@ -30,6 +32,7 @@
30#include <ctype.h> 32#include <ctype.h>
31#include <errno.h> 33#include <errno.h>
32#include <arpa/inet.h> 34#include <arpa/inet.h>
35#include <linux/fs.h>
33#include <linux/connector.h> 36#include <linux/connector.h>
34#include <linux/hyperv.h> 37#include <linux/hyperv.h>
35#include <linux/netlink.h> 38#include <linux/netlink.h>
@@ -44,21 +47,35 @@ static struct sockaddr_nl addr;
44#endif 47#endif
45 48
46 49
50static int vss_do_freeze(char *dir, unsigned int cmd, char *fs_op)
51{
52 int ret, fd = open(dir, O_RDONLY);
53
54 if (fd < 0)
55 return 1;
56 ret = ioctl(fd, cmd, 0);
57 syslog(LOG_INFO, "VSS: %s of %s: %s\n", fs_op, dir, strerror(errno));
58 close(fd);
59 return !!ret;
60}
61
47static int vss_operate(int operation) 62static int vss_operate(int operation)
48{ 63{
49 char *fs_op; 64 char *fs_op;
50 char cmd[512];
51 char match[] = "/dev/"; 65 char match[] = "/dev/";
52 FILE *mounts; 66 FILE *mounts;
53 struct mntent *ent; 67 struct mntent *ent;
68 unsigned int cmd;
54 int error = 0, root_seen = 0; 69 int error = 0, root_seen = 0;
55 70
56 switch (operation) { 71 switch (operation) {
57 case VSS_OP_FREEZE: 72 case VSS_OP_FREEZE:
58 fs_op = "-f "; 73 cmd = FIFREEZE;
74 fs_op = "freeze";
59 break; 75 break;
60 case VSS_OP_THAW: 76 case VSS_OP_THAW:
61 fs_op = "-u "; 77 cmd = FITHAW;
78 fs_op = "thaw";
62 break; 79 break;
63 default: 80 default:
64 return -1; 81 return -1;
@@ -75,16 +92,12 @@ static int vss_operate(int operation)
75 root_seen = 1; 92 root_seen = 1;
76 continue; 93 continue;
77 } 94 }
78 snprintf(cmd, sizeof(cmd), "fsfreeze %s '%s'", fs_op, ent->mnt_dir); 95 error |= vss_do_freeze(ent->mnt_dir, cmd, fs_op);
79 syslog(LOG_INFO, "VSS cmd is %s\n", cmd);
80 error |= system(cmd);
81 } 96 }
82 endmntent(mounts); 97 endmntent(mounts);
83 98
84 if (root_seen) { 99 if (root_seen) {
85 sprintf(cmd, "fsfreeze %s /", fs_op); 100 error |= vss_do_freeze("/", cmd, fs_op);
86 syslog(LOG_INFO, "VSS cmd is %s\n", cmd);
87 error |= system(cmd);
88 } 101 }
89 102
90 return error; 103 return error;