public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dexuan Cui <decui@microsoft.com>
To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	driverdev-devel@linuxdriverproject.org, olaf@aepfle.de,
	apw@canonical.com, jasowang@redhat.com
Cc: kys@microsoft.com, haiyangz@microsoft.com
Subject: [PATCH v2] Tools: hv: vssdaemon: ignore the EBUSY on multiple freezing the same partition
Date: Mon, 22 Sep 2014 22:00:55 -0700	[thread overview]
Message-ID: <1411448455-12768-1-git-send-email-decui@microsoft.com> (raw)

v2: I added "errno = 0;" in the ioctl()

Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: K. Y. Srinivasan <kys@microsoft.com>
---
 tools/hv/hv_vss_daemon.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c
index 6a213b8..c1af658 100644
--- a/tools/hv/hv_vss_daemon.c
+++ b/tools/hv/hv_vss_daemon.c
@@ -50,7 +50,35 @@ static int vss_do_freeze(char *dir, unsigned int cmd, char *fs_op)
 
 	if (fd < 0)
 		return 1;
+
+	/* A successful syscall doesn't set errno to 0. Without this line,
+	 * the below strerror(errno) can accidently show the errno of the
+	 * previous failed syscall.
+	 */
+	errno = 0;
+
 	ret = ioctl(fd, cmd, 0);
+
+	/*
+	 * If a partition is mounted more than once, only the first
+	 * FREEZE/THAW can succeed and the later ones will get
+	 * EBUSY/EINVAL respectively: there could be 2 cases:
+	 * 1) a user may mount the same partition to differnt directories
+	 *  by mistake or on purpose;
+	 * 2) The subvolume of btrfs appears to have the same partition
+	 * mounted more than once.
+	 */
+	if (ret) {
+		if ((cmd == FIFREEZE && errno == EBUSY) ||
+		    (cmd == FITHAW && errno == EINVAL)) {
+			syslog(LOG_INFO, "VSS: %s of %s: %s: ignored\n",
+				fs_op, dir,
+				errno == EBUSY ? "EBUSY" : "EINVAL");
+			close(fd);
+			return 0;
+		}
+	}
+
 	syslog(LOG_INFO, "VSS: %s of %s: %s\n", fs_op, dir, strerror(errno));
 	close(fd);
 	return !!ret;
-- 
1.9.1


             reply	other threads:[~2014-09-23  3:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-23  5:00 Dexuan Cui [this message]
2014-09-23  4:05 ` [PATCH v2] Tools: hv: vssdaemon: ignore the EBUSY on multiple freezing the same partition Dexuan Cui
2014-09-24  6:32 ` Greg KH
2014-09-24  8:57   ` Dexuan Cui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1411448455-12768-1-git-send-email-decui@microsoft.com \
    --to=decui@microsoft.com \
    --cc=apw@canonical.com \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=haiyangz@microsoft.com \
    --cc=jasowang@redhat.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olaf@aepfle.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox