linux-um archives
 help / color / mirror / Atom feed
From: "Paolo 'Blaisorblade' Giarrusso" <blaisorblade@yahoo.it>
To: Andrew Morton <akpm@osdl.org>
Cc: Jeff Dike <jdike@addtoit.com>,
	linux-kernel@vger.kernel.org,
	user-mode-linux-devel@lists.sourceforge.net
Subject: [uml-devel] [PATCH 8/9] uml: allow again to move backing file and to override saved location
Date: Wed, 18 Jan 2006 01:19:47 +0100	[thread overview]
Message-ID: <20060118001946.14622.28532.stgit@zion.home.lan> (raw)
In-Reply-To: <20060117235659.14622.18544.stgit@zion.home.lan>


When the user specifies both a COW file and its backing file, if the previous
backing file is not found, currently UML tries again to use it and fails.

This can be corrected by changing same_backing_files() return value in that
case, so that the caller will try to change the COW file to point to the new
location, as already done in other cases.

Additionally, given the change in the meaning of the func, change its name,
invert its return value, so all values are inverted except when
stat(from_cow,&buf2) fails. And add some comments and two minor bugfixes -
remove a fd leak (return err rather than goto out) and a repeated check.

Tested well.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 arch/um/drivers/ubd_kern.c |   28 +++++++++++++++-------------
 1 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index 49dda56..e498f34 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -1109,31 +1109,33 @@ static int ubd_ioctl(struct inode * inod
 	return(-EINVAL);
 }
 
-static int same_backing_files(char *from_cmdline, char *from_cow, char *cow)
+static int path_requires_switch(char *from_cmdline, char *from_cow, char *cow)
 {
 	struct uml_stat buf1, buf2;
 	int err;
 
-	if(from_cmdline == NULL) return(1);
-	if(!strcmp(from_cmdline, from_cow)) return(1);
+	if(from_cmdline == NULL)
+		return 0;
+	if(!strcmp(from_cmdline, from_cow))
+		return 0;
 
 	err = os_stat_file(from_cmdline, &buf1);
 	if(err < 0){
 		printk("Couldn't stat '%s', err = %d\n", from_cmdline, -err);
-		return(1);
+		return 0;
 	}
 	err = os_stat_file(from_cow, &buf2);
 	if(err < 0){
 		printk("Couldn't stat '%s', err = %d\n", from_cow, -err);
-		return(1);
+		return 1;
 	}
 	if((buf1.ust_dev == buf2.ust_dev) && (buf1.ust_ino == buf2.ust_ino))
-		return(1);
+		return 0;
 
 	printk("Backing file mismatch - \"%s\" requested,\n"
 	       "\"%s\" specified in COW header of \"%s\"\n",
 	       from_cmdline, from_cow, cow);
-	return(0);
+	return 1;
 }
 
 static int backing_file_mismatch(char *file, __u64 size, time_t mtime)
@@ -1195,7 +1197,7 @@ int open_ubd_file(char *file, struct ope
 	unsigned long long size;
 	__u32 version, align;
 	char *backing_file;
-	int fd, err, sectorsize, same, mode = 0644;
+	int fd, err, sectorsize, asked_switch, mode = 0644;
 
 	fd = os_open_file(file, *openflags, mode);
 	if(fd < 0){
@@ -1215,6 +1217,7 @@ int open_ubd_file(char *file, struct ope
 		goto out_close;
 	}
 
+	/* Succesful return case! */
 	if(backing_file_out == NULL) return(fd);
 
 	err = read_cow_header(file_reader, &fd, &version, &backing_file, &mtime,
@@ -1226,17 +1229,16 @@ int open_ubd_file(char *file, struct ope
 	}
 	if(err) return(fd);
 
-	if(backing_file_out == NULL) return(fd);
-
-	same = same_backing_files(*backing_file_out, backing_file, file);
+	asked_switch = path_requires_switch(*backing_file_out, backing_file, file);
 
-	if(!same && !backing_file_mismatch(*backing_file_out, size, mtime)){
+	/* Allow switching only if no mismatch. */
+	if (asked_switch && !backing_file_mismatch(*backing_file_out, size, mtime)) {
 		printk("Switching backing file to '%s'\n", *backing_file_out);
 		err = write_cow_header(file, fd, *backing_file_out,
 				       sectorsize, align, &size);
 		if(err){
 			printk("Switch failed, errno = %d\n", -err);
-			return(err);
+			goto out_close;
 		}
 	}
 	else {



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

  parent reply	other threads:[~2006-01-18  0:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20060117235659.14622.18544.stgit@zion.home.lan>
2006-01-18  0:19 ` [uml-devel] [PATCH 1/9] uml: avoid sysfs warning on hot-unplug Paolo 'Blaisorblade' Giarrusso
2006-01-18  2:53   ` [uml-devel] " Jeff Dike
2006-01-18 11:11     ` Blaisorblade
2006-01-18  0:19 ` [uml-devel] [PATCH 2/9] uml: make daemon transport behave properly Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:19 ` [uml-devel] [PATCH 3/9] uml: networking - clear transport-specific structure Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:19 ` [uml-devel] [PATCH 4/9] uml: fix spinlock recursion and sleep-inside-spinlock in error path Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:52   ` [uml-devel] " Andrew Morton
2006-01-18 11:44     ` Blaisorblade
2006-01-18  0:19 ` [uml-devel] [PATCH 5/9] uml: sigio code - reduce spinlock hold time Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:19 ` [uml-devel] [PATCH 6/9] uml: avoid malloc to sleep in atomic sections Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:56   ` [uml-devel] " Andrew Morton
2006-01-18 11:47     ` Blaisorblade
2006-01-18  0:19 ` [uml-devel] [PATCH 7/9] uml: arch Kconfig menu cleanups Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:19 ` Paolo 'Blaisorblade' Giarrusso [this message]
2006-01-18  0:19 ` [uml-devel] [PATCH 9/9] uml ubd code: fix a bit of whitespace Paolo 'Blaisorblade' Giarrusso

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=20060118001946.14622.28532.stgit@zion.home.lan \
    --to=blaisorblade@yahoo.it \
    --cc=akpm@osdl.org \
    --cc=jdike@addtoit.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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