Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755537Ab3DXOQ2 (ORCPT ); Wed, 24 Apr 2013 10:16:28 -0400 Received: from p3plsmtps2ded04.prod.phx3.secureserver.net ([208.109.80.198]:35366 "EHLO p3plsmtps2ded04.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755157Ab3DXOQY (ORCPT ); Wed, 24 Apr 2013 10:16:24 -0400 x-originating-ip: 72.167.245.219 From: "K. Y. Srinivasan" To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, jasowang@redhat.com Cc: "K. Y. Srinivasan" Subject: [PATCH 5/7] tools: hv: use FIFREEZE/FITHAW in hv_vss_daemon Date: Wed, 24 Apr 2013 07:48:52 -0700 Message-Id: <1366814934-4461-5-git-send-email-kys@microsoft.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1366814934-4461-1-git-send-email-kys@microsoft.com> References: <1366814913-4422-1-git-send-email-kys@microsoft.com> <1366814934-4461-1-git-send-email-kys@microsoft.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2413 Lines: 98 From: Olaf Hering As suggested by Paolo Bonzini, use ioctl instead of calling fsfreeze. Signed-off-by: Olaf Hering Signed-off-by: K. Y. Srinivasan --- tools/hv/hv_vss_daemon.c | 31 ++++++++++++++++++++++--------- 1 files changed, 22 insertions(+), 9 deletions(-) diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c index a5da91d..dc73a89 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; -- 1.7.4.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/