Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Oct 2012 12:14:59 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r241809 - in head/sys/boot: common i386/libi386 uboot/lib userboot/userboot
Message-ID:  <201210211214.q9LCExqi071578@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Sun Oct 21 12:14:58 2012
New Revision: 241809
URL: http://svn.freebsd.org/changeset/base/241809

Log:
  Add the flags parameter to the disk_open() function and DISK_F_NOCACHE
  flag, that disables the caching of partition tables metadata.
  Use this flag for floppies in the libi386/biosdisk driver.

Modified:
  head/sys/boot/common/disk.c
  head/sys/boot/common/disk.h
  head/sys/boot/i386/libi386/biosdisk.c
  head/sys/boot/uboot/lib/disk.c
  head/sys/boot/userboot/userboot/userboot_disk.c

Modified: head/sys/boot/common/disk.c
==============================================================================
--- head/sys/boot/common/disk.c	Sun Oct 21 12:12:22 2012	(r241808)
+++ head/sys/boot/common/disk.c	Sun Oct 21 12:14:58 2012	(r241809)
@@ -47,6 +47,7 @@ struct open_disk {
 	struct ptable		*table;
 	off_t			mediasize;
 	u_int			sectorsize;
+	u_int			flags;
 	int			rcnt;
 };
 
@@ -232,16 +233,20 @@ disk_print(struct disk_devdesc *dev, cha
 }
 
 int
-disk_open(struct disk_devdesc *dev, off_t mediasize, u_int sectorsize)
+disk_open(struct disk_devdesc *dev, off_t mediasize, u_int sectorsize,
+    u_int flags)
 {
 	struct open_disk *od;
 	struct ptable *table;
 	struct ptable_entry part;
 	int rc, slice, partition;
 
-	rc = disk_lookup(dev);
-	if (rc == 0)
-		return (0);
+	rc = 0;
+	if ((flags & DISK_F_NOCACHE) == 0) {
+		rc = disk_lookup(dev);
+		if (rc == 0)
+			return (0);
+	}
 	/*
 	 * While we are reading disk metadata, make sure we do it relative
 	 * to the start of the disk
@@ -267,11 +272,12 @@ disk_open(struct disk_devdesc *dev, off_
 			DEBUG("no memory");
 			return (ENOMEM);
 		}
+		dev->d_opendata = od;
+		od->rcnt = 0;
 	}
-	dev->d_opendata = od;
 	od->mediasize = mediasize;
 	od->sectorsize = sectorsize;
-	od->rcnt = 0;
+	od->flags = flags;
 	DEBUG("%s unit %d, slice %d, partition %d => %p",
 	    disk_fmtdev(dev), dev->d_unit, dev->d_slice, dev->d_partition, od);
 
@@ -348,7 +354,8 @@ out:
 		}
 		DEBUG("%s could not open", disk_fmtdev(dev));
 	} else {
-		disk_insert(dev);
+		if ((flags & DISK_F_NOCACHE) == 0)
+			disk_insert(dev);
 		/* Save the slice and partition number to the dev */
 		dev->d_slice = slice;
 		dev->d_partition = partition;
@@ -361,12 +368,14 @@ out:
 int
 disk_close(struct disk_devdesc *dev)
 {
-#if DISK_DEBUG
 	struct open_disk *od;
 
 	od = (struct open_disk *)dev->d_opendata;
 	DEBUG("%s closed => %p [%d]", disk_fmtdev(dev), od, od->rcnt);
-#endif
+	if (od->flags & DISK_F_NOCACHE) {
+		ptable_close(od->table);
+		free(od);
+	}
 	return (0);
 }
 

Modified: head/sys/boot/common/disk.h
==============================================================================
--- head/sys/boot/common/disk.h	Sun Oct 21 12:12:22 2012	(r241808)
+++ head/sys/boot/common/disk.h	Sun Oct 21 12:14:58 2012	(r241809)
@@ -93,7 +93,8 @@ struct disk_devdesc
  * Parse disk metadata and initialise dev->d_offset.
  */
 extern int disk_open(struct disk_devdesc *dev, off_t mediasize,
-    u_int sectorsize);
+    u_int sectorsize, u_int flags);
+#define	DISK_F_NOCACHE	0x0001		/* Do not use metadata caching */
 extern int disk_close(struct disk_devdesc *dev);
 extern void disk_cleanup(const struct devsw *d_dev);
 

Modified: head/sys/boot/i386/libi386/biosdisk.c
==============================================================================
--- head/sys/boot/i386/libi386/biosdisk.c	Sun Oct 21 12:12:22 2012	(r241808)
+++ head/sys/boot/i386/libi386/biosdisk.c	Sun Oct 21 12:14:58 2012	(r241809)
@@ -276,7 +276,9 @@ bd_print(int verbose)
 		dev.d_partition = -1;
 		if (disk_open(&dev,
 		    bdinfo[i].bd_sectorsize * bdinfo[i].bd_sectors,
-		    bdinfo[i].bd_sectorsize) == 0) {
+		    bdinfo[i].bd_sectorsize,
+		    (bdinfo[i].bd_flags & BD_FLOPPY) ?
+		    DISK_F_NOCACHE: 0) == 0) {
 			sprintf(line, "    disk%d", i);
 			disk_print(&dev, line, verbose);
 			disk_close(&dev);
@@ -308,7 +310,8 @@ bd_open(struct open_file *f, ...)
 		return (EIO);
 
 	return (disk_open(dev, BD(dev).bd_sectors * BD(dev).bd_sectorsize,
-	    BD(dev).bd_sectorsize));
+	    BD(dev).bd_sectorsize, (BD(dev).bd_flags & BD_FLOPPY) ?
+	    DISK_F_NOCACHE: 0));
 }
 
 static int
@@ -645,7 +648,8 @@ bd_getdev(struct i386_devdesc *d)
     if (biosdev == -1)				/* not a BIOS device */
 	return(-1);
     if (disk_open(dev, BD(dev).bd_sectors * BD(dev).bd_sectorsize,
-	BD(dev).bd_sectorsize) != 0)		/* oops, not a viable device */
+	BD(dev).bd_sectorsize,(BD(dev).bd_flags & BD_FLOPPY) ?
+	DISK_F_NOCACHE: 0) != 0)		/* oops, not a viable device */
 	    return (-1);
     else
 	disk_close(dev);

Modified: head/sys/boot/uboot/lib/disk.c
==============================================================================
--- head/sys/boot/uboot/lib/disk.c	Sun Oct 21 12:12:22 2012	(r241808)
+++ head/sys/boot/uboot/lib/disk.c	Sun Oct 21 12:14:58 2012	(r241809)
@@ -205,7 +205,7 @@ stor_opendev(struct disk_devdesc *dev)
 		SI(dev).opened++;
 	}
 	return (disk_open(dev, SI(dev).blocks * SI(dev).bsize,
-	    SI(dev).bsize));
+	    SI(dev).bsize, 0));
 }
 
 static int

Modified: head/sys/boot/userboot/userboot/userboot_disk.c
==============================================================================
--- head/sys/boot/userboot/userboot/userboot_disk.c	Sun Oct 21 12:12:22 2012	(r241808)
+++ head/sys/boot/userboot/userboot/userboot_disk.c	Sun Oct 21 12:14:58 2012	(r241809)
@@ -125,7 +125,7 @@ userdisk_print(int verbose)
 		dev.d_slice = -1;
 		dev.d_partition = -1;
 		if (disk_open(&dev, ud_info[i].mediasize,
-		    ud_info[i].sectorsize) == 0) {
+		    ud_info[i].sectorsize, 0) == 0) {
 			sprintf(line, "    disk%d", i);
 			disk_print(&dev, line, verbose);
 			disk_close(&dev);
@@ -150,7 +150,7 @@ userdisk_open(struct open_file *f, ...)
 		return (EIO);
 
 	return (disk_open(dev, ud_info[dev->d_unit].mediasize,
-	    ud_info[dev->d_unit].sectorsize));
+	    ud_info[dev->d_unit].sectorsize, 0));
 }
 
 static int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201210211214.q9LCExqi071578>