From: Olaf Hering Date: Wed, 24 Apr 2013 14:48:52 +0000 (-0700) Subject: tools: hv: use FIFREEZE/FITHAW in hv_vss_daemon X-Git-Tag: firefly_0821_release~3680^2~676^2~2 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7b413b65531422cc3d12a8acf53a43bc0d3c9f7b;p=firefly-linux-kernel-4.4.55.git 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 Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- 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 @@ #include #include #include +#include #include +#include #include #include #include @@ -30,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -44,21 +47,35 @@ static struct sockaddr_nl addr; #endif +static int vss_do_freeze(char *dir, unsigned int cmd, char *fs_op) +{ + int ret, fd = open(dir, O_RDONLY); + + if (fd < 0) + return 1; + ret = ioctl(fd, cmd, 0); + syslog(LOG_INFO, "VSS: %s of %s: %s\n", fs_op, dir, strerror(errno)); + close(fd); + return !!ret; +} + static int vss_operate(int operation) { char *fs_op; - char cmd[512]; char match[] = "/dev/"; FILE *mounts; struct mntent *ent; + unsigned int cmd; int error = 0, root_seen = 0; switch (operation) { case VSS_OP_FREEZE: - fs_op = "-f "; + cmd = FIFREEZE; + fs_op = "freeze"; break; case VSS_OP_THAW: - fs_op = "-u "; + cmd = FITHAW; + fs_op = "thaw"; break; default: return -1; @@ -75,16 +92,12 @@ static int vss_operate(int operation) root_seen = 1; continue; } - snprintf(cmd, sizeof(cmd), "fsfreeze %s '%s'", fs_op, ent->mnt_dir); - syslog(LOG_INFO, "VSS cmd is %s\n", cmd); - error |= system(cmd); + error |= vss_do_freeze(ent->mnt_dir, cmd, fs_op); } endmntent(mounts); if (root_seen) { - sprintf(cmd, "fsfreeze %s /", fs_op); - syslog(LOG_INFO, "VSS cmd is %s\n", cmd); - error |= system(cmd); + error |= vss_do_freeze("/", cmd, fs_op); } return error;