Clobbering foreign partitions
Arun Sharma
arun at freebsd.org
Sun Jun 27 20:59:28 PDT 2004
John Baldwin wrote:
>
> Looks ok to me. Marcel, do you think you can test this?
>
I also hacked the md driver so that I could test these scenerios without a second disk. The patch is attached.
Since my ia64 box is currently having disk problems, I had to do the testing on i386 hardware, by compiling sysinstall/libdisk with -D__ia64__ -U__i386__. Certainly this needs to be revalidated on real ia64 hardware.
-Arun
-------------- next part --------------
Index: md.c
===================================================================
RCS file: /net/eagle/home/scratch/freebsd/src/sys/dev/md/md.c,v
retrieving revision 1.123
diff -u -r1.123 md.c
--- md.c 18 May 2004 07:30:04 -0000 1.123
+++ md.c 25 Jun 2004 16:22:59 -0000
@@ -60,6 +60,7 @@
#include <sys/systm.h>
#include <sys/bio.h>
#include <sys/conf.h>
+#include <sys/disk.h>
#include <sys/fcntl.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
@@ -76,6 +77,7 @@
#include <sys/vnode.h>
#include <geom/geom.h>
+#include <geom/geom_disk.h>
#include <vm/vm.h>
#include <vm/vm_object.h>
@@ -165,6 +167,8 @@
/* MD_SWAP related fields */
vm_object_t object;
unsigned npage;
+
+ struct disk *disk; /* disklabel/slice stuff */
};
static int mddestroy(struct md_s *sc, struct thread *td);
@@ -359,6 +363,36 @@
return (0);
}
+
+static int
+mdopen(struct disk *dp)
+{
+ struct md_s *sc;
+
+ sc = dp->d_drv1;
+ if (sc == NULL || sc->flags & MD_SHUTDOWN)
+ return ENXIO;
+ return 0;
+}
+
+static void
+mdstrategy(struct bio *bp)
+{
+ struct md_s *sc;
+
+ sc = bp->bio_disk->d_drv1;
+
+ if (sc->flags & MD_SHUTDOWN) {
+ biofinish(bp, NULL, ENXIO);
+ return;
+ }
+
+ mtx_lock(&sc->queue_mtx);
+ bioq_disksort(&sc->bio_queue, bp);
+ mtx_unlock(&sc->queue_mtx);
+ wakeup(sc);
+}
+
static void
g_md_start(struct bio *bp)
{
@@ -377,7 +411,6 @@
DECLARE_GEOM_CLASS(g_md_class, g_md);
-
static int
mdstart_malloc(struct md_s *sc, struct bio *bp)
{
@@ -509,6 +542,8 @@
vn_finished_write(mp);
}
bp->bio_resid = auio.uio_resid;
+ biodone(bp);
+
return (error);
}
@@ -656,7 +691,7 @@
}
}
- if (error != -1) {
+ if ((error != -1) && (sc->type != MD_VNODE)) {
bp->bio_completed = bp->bio_length;
g_io_deliver(bp, error);
}
@@ -940,7 +975,20 @@
mddestroy(sc, td);
return (error);
}
- mdinit(sc);
+
+ /* lets create the disk device */
+ sc->disk = disk_alloc();
+ sc->disk->d_name = "md";
+ sc->disk->d_drv1 = sc;
+ sc->disk->d_maxsize = DFLTPHYS;
+ sc->disk->d_sectorsize = sc->secsize;
+ sc->disk->d_mediasize = (off_t) sc->secsize * sc->nsect;
+ sc->disk->d_fwsectors = sc->nsect;
+ sc->disk->d_fwheads = sc->fwheads;
+ sc->disk->d_unit = sc->unit;
+ sc->disk->d_strategy = mdstrategy;
+ sc->disk->d_open = mdopen;
+ disk_create(sc->disk, DISK_VERSION);
return (0);
}
@@ -982,6 +1030,8 @@
if (sc->uma)
uma_zdestroy(sc->uma);
+ if (sc->disk)
+ disk_destroy(sc->disk);
/* XXX: LOCK(unique unit numbers) */
LIST_REMOVE(sc, list);
/* XXX: UNLOCK(unique unit numbers) */
More information about the freebsd-ia64
mailing list