Deleted Added
sdiff udiff text old ( 63309 ) new ( 64880 )
full compact
1/*
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 *
9 * $FreeBSD: head/sys/dev/md/md.c 63309 2000-07-17 13:13:04Z sheldonh $
10 *
11 */
12
13#include "opt_mfs.h" /* We have adopted some tasks from MFS */
14#include "opt_md.h" /* We have adopted some tasks from MFS */
15
16#include <sys/param.h>
17#include <sys/systm.h>
18#include <sys/bio.h>
19#include <sys/conf.h>
20#include <sys/devicestat.h>
21#include <sys/disk.h>
22#include <sys/kernel.h>
23#include <sys/malloc.h>
24#include <sys/sysctl.h>
25#include <sys/linker.h>
26
27#ifndef MD_NSECT
28#define MD_NSECT (10000 * 2)
29#endif
30
31MALLOC_DEFINE(M_MD, "MD disk", "Memory Disk");
32MALLOC_DEFINE(M_MDSECT, "MD sectors", "Memory Disk Sectors");
33
34static int md_debug;

--- 12 unchanged lines hidden (view full) ---

47#if defined(MD_ROOT) && defined(MD_ROOT_SIZE)
48/* Image gets put here: */
49static u_char mfs_root[MD_ROOT_SIZE*1024] = "MFS Filesystem goes here";
50static u_char end_mfs_root[] __unused = "MFS Filesystem had better STOP here";
51#endif
52
53static int mdrootready;
54
55static void mdcreate_malloc(void);
56
57#define CDEV_MAJOR 95
58#define BDEV_MAJOR 22
59
60static d_strategy_t mdstrategy;
61static d_strategy_t mdstrategy_preload;
62static d_strategy_t mdstrategy_malloc;
63static d_open_t mdopen;

--- 13 unchanged lines hidden (view full) ---

77 /* dump */ nodump,
78 /* psize */ nopsize,
79 /* flags */ D_DISK | D_CANFREE | D_MEMDISK,
80 /* bmaj */ BDEV_MAJOR
81};
82
83static struct cdevsw mddisk_cdevsw;
84
85struct md_s {
86 int unit;
87 struct devstat stats;
88 struct bio_queue_head bio_queue;
89 struct disk disk;
90 dev_t dev;
91 int busy;
92 enum {MD_MALLOC, MD_PRELOAD} type;
93 unsigned nsect;
94

--- 14 unchanged lines hidden (view full) ---

109 struct md_s *sc;
110 struct disklabel *dl;
111
112 if (md_debug)
113 printf("mdopen(%s %x %x %p)\n",
114 devtoname(dev), flag, fmt, p);
115
116 sc = dev->si_drv1;
117 if (sc->unit + 1 == mdunits)
118 mdcreate_malloc();
119
120 dl = &sc->disk.d_label;
121 bzero(dl, sizeof(*dl));
122 dl->d_secsize = DEV_BSIZE;
123 dl->d_nsectors = 1024;
124 dl->d_ntracks = 1;
125 dl->d_secpercyl = dl->d_nsectors * dl->d_ntracks;
126 dl->d_secperunit = sc->nsect;

--- 209 unchanged lines hidden (view full) ---

336 biodone(bp);
337 s = splbio();
338 }
339 sc->busy = 0;
340 return;
341}
342
343static struct md_s *
344mdcreate(void)
345{
346 struct md_s *sc;
347
348 MALLOC(sc, struct md_s *,sizeof(*sc), M_MD, M_WAITOK);
349 bzero(sc, sizeof(*sc));
350 sc->unit = mdunits++;
351 bioq_init(&sc->bio_queue);
352 devstat_add_entry(&sc->stats, "md", sc->unit, DEV_BSIZE,
353 DEVSTAT_NO_ORDERED_TAGS,
354 DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER,
355 DEVSTAT_PRIORITY_OTHER);
356 sc->dev = disk_create(sc->unit, &sc->disk, 0, &md_cdevsw, &mddisk_cdevsw);
357 sc->dev->si_drv1 = sc;
358 return (sc);
359}
360
361static void
362mdcreate_preload(u_char *image, unsigned length)
363{
364 struct md_s *sc;
365
366 sc = mdcreate();
367 sc->type = MD_PRELOAD;
368 sc->nsect = length / DEV_BSIZE;
369 sc->pl_ptr = image;
370 sc->pl_len = length;
371
372 if (sc->unit == 0)
373 mdrootready = 1;
374}
375
376static void
377mdcreate_malloc(void)
378{
379 struct md_s *sc;
380
381 sc = mdcreate();
382 sc->type = MD_MALLOC;
383
384 sc->nsect = MD_NSECT; /* for now */
385 MALLOC(sc->secp, u_char **, sizeof(u_char *), M_MD, M_WAITOK);
386 bzero(sc->secp, sizeof(u_char *));
387 sc->nsecp = 1;
388 printf("md%d: Malloc disk\n", sc->unit);
389}
390
391static void
392md_drvinit(void *unused)
393{
394
395 caddr_t mod;
396 caddr_t c;
397 u_char *ptr, *name, *type;
398 unsigned len;
399

--- 13 unchanged lines hidden (view full) ---

413 c = preload_search_info(mod, MODINFO_ADDR);
414 ptr = *(u_char **)c;
415 c = preload_search_info(mod, MODINFO_SIZE);
416 len = *(unsigned *)c;
417 printf("md%d: Preloaded image <%s> %d bytes at %p\n",
418 mdunits, name, len, ptr);
419 mdcreate_preload(ptr, len);
420 }
421 mdcreate_malloc();
422}
423
424SYSINIT(mddev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, md_drvinit,NULL)
425
426#ifdef MD_ROOT
427static void
428md_takeroot(void *junk)
429{
430 if (mdrootready)
431 rootdevnames[0] = "ufs:/dev/md0c";
432}
433
434SYSINIT(md_root, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, md_takeroot, NULL);
435#endif