Skip to contentSkip to conversation

uml ubd: handle readonly status

PATCH In review [email protected] 2 participants 4 messages Apr 24, 2005 – Apr 26, 2005 User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

PATCH 7/7 uml ubd: handle readonly status

CC Jens Axboe <[email protected]>

Use the set_disk_ro() API when the backing file is read-only, to mark the disk read-only, during the ->open(). The current hack does not work when doing a mount -o remount.

Also, upgrade some warnings to WARN_ON(1) statements. They should actually become BUG()s probably but I'll avoid that since I'm not so sure the change works so well. I gave it only some limited testing.

---

 linux-2.6.12-paolo/arch/um/drivers/ubd_kern.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
arch/um/drivers/ubd_kern.c renamed from arch/um/drivers/ubd_kern.c~uml-ubd-handle-readonly +10 -4
diff -puN arch/um/drivers/ubd_kern.c~uml-ubd-handle-readonly arch/um/drivers/ubd_kern.c
@@ -156,6 +156,7 @@ static struct gendisk *fake_gendisk[MAX_
 static struct openflags global_openflags = OPEN_FLAGS;
 
 struct cow {
+	/* This is the backing file, actually */
 	char *file;
 	int fd;
 	unsigned long *bitmap;
@@ -927,10 +928,14 @@ static int ubd_open(struct inode *inode,
 		}
 	}
 	dev->count++;
-	if((filp->f_mode & FMODE_WRITE) && !dev->openflags.w){
+	set_disk_ro(disk, !dev->openflags.w);
+
+	/* This should no more be needed. And it didn't work anyway to exclude
+	 * read-write remounting of filesystems.*/
+	/*if((filp->f_mode & FMODE_WRITE) && !dev->openflags.w){
 	        if(--dev->count == 0) ubd_close(dev);
 	        err = -EROFS;
-	}
+	}*/
  out:
 	return(err);
 }
@@ -1099,6 +1104,7 @@ static int prepare_request(struct reques
 	if((rq_data_dir(req) == WRITE) && !dev->openflags.w){
 		printk("Write attempted on readonly ubd device %s\n", 
 		       disk->disk_name);
+		WARN_ON(1); /* This should be impossible now */
 		end_request(req, 0);
 		return(1);
 	}
@@ -1252,6 +1258,7 @@ static int ubd_check_remapped(int fd, un
 			 */
 			printk("Write access to mapped page from readonly ubd "
 			       "device %d\n", i);
+			WARN_ON(1); /* This should be impossible now */
 			return(0);
 		}
 
@@ -1605,8 +1612,7 @@ void do_io(struct io_thread_req *req)
 				}
 			} while((n < len) && (n != 0));
 			if (n < len) memset(&buf[n], 0, len - n);
-		}
-		else {
+		} else {
 			n = os_write_file(req->fds[bit], buf, len);
 			if(n != len){
 				printk("do_io - write failed err = %d "

_

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#1 lore raw

arch/um/drivers/ubd_kern.c static int prepare_request(struct reques · line 1110

Quoted 8 lines · On Sun, Apr 24 2005, [email protected] wrote:
arch/um/drivers/ubd_kern.c renamed from arch/um/drivers/ubd_kern.c~uml-ubd-handle-readonly +1 -0
@@ -1099,6 +1104,7 @@ static int prepare_request(struct reques
 	if((rq_data_dir(req) == WRITE) && !dev->openflags.w){
 		printk("Write attempted on readonly ubd device %s\n", 
 		       disk->disk_name);
+		WARN_ON(1); /* This should be impossible now */
 		end_request(req, 0);
 		return(1);
 	}

I don't think that's a sound change. The WARN_ON() is strictly only really useful for when you need the stack trace for something interesting. As the io happens async, you will get a boring trace that doesn't contain any valuable information.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 14 lines · Jens Axboe

arch/um/drivers/ubd_kern.c static int prepare_request(struct reques · line 1110

Quoted 8 lines · On Sun, Apr 24 2005, [email protected] wrote:
arch/um/drivers/ubd_kern.c renamed from arch/um/drivers/ubd_kern.c~uml-ubd-handle-readonly +1 -0
@@ -1099,6 +1104,7 @@ static int prepare_request(struct reques
 	if((rq_data_dir(req) == WRITE) && !dev->openflags.w){
 		printk("Write attempted on readonly ubd device %s\n",
 		       disk->disk_name);
+		WARN_ON(1); /* This should be impossible now */
 		end_request(req, 0);
 		return(1);
 	}

I don't think that's a sound change. The WARN_ON() is strictly only really useful for when you need the stack trace for something interesting. As the io happens async, you will get a boring trace that doesn't contain any valuable information.

Ok, removed, and resending the patch, is the rest ok? I.e. is that supposed to work? I gave a walk around and it seemed that the code handles set_{disk,device}_ro() even during the open, but I'm no block layer expert.

Thanks for the review.

Signature · 17 lines
Paolo Giarrusso, aka Blaisorblade
Skype user "PaoloGiarrusso"
Linux registered user n. 292729
http://www.user-mode-linux.org/~blaisorblade




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#3 lore raw
Quoted 15 lines · Blaisorblade
Quoted 14 lines · Jens Axboe

arch/um/drivers/ubd_kern.c static int prepare_request(struct reques · line 1110

Quoted 8 lines · On Sun, Apr 24 2005, [email protected] wrote:
arch/um/drivers/ubd_kern.c renamed from arch/um/drivers/ubd_kern.c~uml-ubd-handle-readonly +1 -0
@@ -1099,6 +1104,7 @@ static int prepare_request(struct reques
 	if((rq_data_dir(req) == WRITE) && !dev->openflags.w){
 		printk("Write attempted on readonly ubd device %s\n",
 		       disk->disk_name);
+		WARN_ON(1); /* This should be impossible now */
 		end_request(req, 0);
 		return(1);
 	}

I don't think that's a sound change. The WARN_ON() is strictly only really useful for when you need the stack trace for something interesting. As the io happens async, you will get a boring trace that doesn't contain any valuable information.

Quoted 4 lines

Ok, removed, and resending the patch, is the rest ok? I.e. is that supposed to work? I gave a walk around and it seemed that the code handles set_{disk,device}_ro() even during the open, but I'm no block layer expert.

I'd keep the checks for sanity. Although the set_disk/device_ro prevents regular fs write mounts, a buggy layered drive could still send down a write by accident.

Signature · 13 lines
Jens Axboe



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel