tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Module problem on amd64 (fwd)



Probably this is a better forum for this discussion...

Background: Kernels configured with explicit filesystem type, fail to build if the filesystem is not compiled into the kernel proper (ie, it's available only as a loadable module).

Since we already have all the code to search through the available modules, there's no good reason to require the root filesystem to be linked in at build time. We can simply identify the root filesystem by its name, and search-and-load at boot time.

The attached patches completely remove the global mount_root variable, and instead implements a rootfstype variable. I've tested it with one of my standard systems, using four different configurations:

        TEST1 and TEST3 have 'config root on ... type ?'
        TEST2 and TEST4 have 'config root on ... type ffs'

        TEST1 and TEST2 have no file-system FFS configured
        TEST3 and TEST4 have file-system FFS configured, as well as
        several others.

        All four systems have 'options MODULAR' defined.

Both TEST3 and TEST4 boot successfully, all the way to multi-user.

TEST1 and TEST2 boot successfully to single user, and I'm able to do a 'ls' command from the single-user shell prompt. However, both of these panic due to the "end <= VM_MAX_KERNEL_ADDRESS" thing mentioned in an earlier thread; this panic fires off as soon as the kernel tries to unload a module.

I've not tried to boot via nfs, nor have I tried a root_is_mfs kernel; both of these should probably be tested since there are special cases for them in a couple of places. If anyone is willing to test them, I'd certainly appreciate it.

I'd also appreciate any other feedback/comments/code-review/etc. that anyone is willing to offer, especially as it might relate to whether or not these changes should be committed to -current.

Thanks!


----------------------------------------------------------------------
|   Paul Goyette   | PGP DSS Key fingerprint: |  E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 |  paul%whooppee.com@localhost   |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette%juniper.net@localhost |
----------------------------------------------------------------------
Index: sys/kern/vfs_subr.c
===================================================================
RCS file: /cvsroot/src/sys/kern/vfs_subr.c,v
retrieving revision 1.357
diff -u -p -r1.357 vfs_subr.c
--- sys/kern/vfs_subr.c 24 Sep 2008 09:33:40 -0000      1.357
+++ sys/kern/vfs_subr.c 29 Nov 2008 00:43:46 -0000
@@ -2382,20 +2382,18 @@ vfs_mountroot(void)
        }
 
        /*
-        * If user specified a file system, use it.
-        */
-       if (mountroot != NULL) {
-               error = (*mountroot)();
-               goto done;
-       }
-
-       /*
         * Try each file system currently configured into the kernel.
         */
        mutex_enter(&vfs_list_lock);
        LIST_FOREACH(v, &vfs_list, vfs_list) {
                if (v->vfs_mountroot == NULL)
                        continue;
+               /*
+                * If user specified a file system type, use only
+                * that type
+                */
+               if (strcmp(rootfstype, "?") && strcmp(rootfstype, v->vfs_name))
+                       continue;
 #ifdef DEBUG
                aprint_normal("mountroot: trying %s...\n", v->vfs_name);
 #endif
@@ -2420,7 +2418,6 @@ vfs_mountroot(void)
                error = EFTYPE;
        }
 
-done:
        if (error && device_class(root_device) == DV_DISK) {
                VOP_CLOSE(rootvp, FREAD, FSCRED);
                vrele(rootvp);
Index: sys/kern/kern_subr.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_subr.c,v
retrieving revision 1.196
diff -u -p -r1.196 kern_subr.c
--- sys/kern/kern_subr.c        27 Nov 2008 21:36:51 -0000      1.196
+++ sys/kern/kern_subr.c        29 Nov 2008 00:43:46 -0000
@@ -763,6 +763,7 @@ setroot(struct device *bootdv, int bootp
        struct ifnet *ifp;
        const char *deffsname;
        struct vfsops *vops;
+       static char my_vfs_name[NAME_MAX + 1];
 
 #ifdef TFTPROOT
        if (tftproot_dhcpboot(bootdv) != 0)
@@ -786,7 +787,7 @@ setroot(struct device *bootdv, int bootp
         * find a reasonable network interface for "rootspec".
         */
        vops = vfs_getopsbyname("nfs");
-       if (vops != NULL && vops->vfs_mountroot == mountroot &&
+       if (vops != NULL && strcmp(rootfstype, "nfs") == 0 &&
            rootspec == NULL &&
            (bootdv == NULL || device_class(bootdv) != DV_IFNET)) {
                IFNET_FOREACH(ifp) {
@@ -897,12 +898,14 @@ setroot(struct device *bootdv, int bootp
                for (vops = LIST_FIRST(&vfs_list); vops != NULL;
                     vops = LIST_NEXT(vops, vfs_list)) {
                        if (vops->vfs_mountroot != NULL &&
-                           vops->vfs_mountroot == mountroot)
+                           strcmp(rootfstype, vops->vfs_name) == 0)
                        break;
                }
 
                if (vops == NULL) {
+/*
                        mountroot = NULL;
+*/
                        deffsname = "generic";
                } else
                        deffsname = vops->vfs_name;
@@ -922,7 +925,7 @@ setroot(struct device *bootdv, int bootp
                        }
 #endif
                        else if (len == 7 && strcmp(buf, "generic") == 0) {
-                               mountroot = NULL;
+                               rootfstype = "?";
                                break;
                        }
                        vops = vfs_getopsbyname(buf);
@@ -939,7 +942,13 @@ setroot(struct device *bootdv, int bootp
 #endif
                                printf(" halt reboot\n");
                        } else {
-                               mountroot = vops->vfs_mountroot;
+                               /*
+                                * Copy the vfs_name since *vops might be
+                                * deallocated?
+                                */
+                               strncpy(my_vfs_name, vops->vfs_name,
+                                       sizeof(my_vfs_name));
+                               rootfstype = (const char *)my_vfs_name;
                                vfs_delref(vops);
                                break;
                        }
Index: sys/sys/systm.h
===================================================================
RCS file: /cvsroot/src/sys/sys/systm.h,v
retrieving revision 1.230
diff -u -p -r1.230 systm.h
--- sys/sys/systm.h     12 Nov 2008 14:29:31 -0000      1.230
+++ sys/sys/systm.h     29 Nov 2008 00:43:47 -0000
@@ -333,7 +333,7 @@ void        dopowerhooks(int);
  * these to be executed just before (*mountroot)() if the passed device is
  * selected as the root device.
  */
-extern int (*mountroot)(void);
+extern const char *rootfstype;
 void   *mountroothook_establish(void (*)(struct device *), struct device *);
 void   mountroothook_disestablish(void *);
 void   mountroothook_destroy(void);
Index: sys/rump/librump/rumpvfs/vfsops_stub.c
===================================================================
RCS file: /cvsroot/src/sys/rump/librump/rumpvfs/vfsops_stub.c,v
retrieving revision 1.1
diff -u -p -r1.1 vfsops_stub.c
--- sys/rump/librump/rumpvfs/vfsops_stub.c      19 Nov 2008 14:10:49 -0000      
1.1
+++ sys/rump/librump/rumpvfs/vfsops_stub.c      29 Nov 2008 00:43:47 -0000
@@ -37,7 +37,7 @@
 #include <miscfs/fifofs/fifo.h>
 #include <miscfs/syncfs/syncfs.h>
 
-int (*mountroot)(void);
+const char *rootfstype;
 
 #define VFSSTUB(name)                                                  \
     int name(void *arg) {panic("%s: unimplemented vfs stub", __func__);}
Index: sys/ufs/mfs/mfs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/mfs/mfs_vfsops.c,v
retrieving revision 1.99
diff -u -p -r1.99 mfs_vfsops.c
--- sys/ufs/mfs/mfs_vfsops.c    13 Nov 2008 11:10:41 -0000      1.99
+++ sys/ufs/mfs/mfs_vfsops.c    29 Nov 2008 00:43:47 -0000
@@ -253,7 +253,7 @@ mfs_initminiroot(void *base)
        if (fs->fs_magic != FS_UFS1_MAGIC || fs->fs_bsize > MAXBSIZE ||
            fs->fs_bsize < sizeof(struct fs))
                return (0);
-       mountroot = mfs_mountroot;
+       rootfstype = "mfs";
        mfs_rootbase = base;
        mfs_rootsize = fs->fs_fsize * fs->fs_size;
        rootdev = makedev(255, mfs_minor);
Index: usr.bin/config/mkswap.c
===================================================================
RCS file: /cvsroot/src/usr.bin/config/mkswap.c,v
retrieving revision 1.4
diff -u -p -r1.4 mkswap.c
--- usr.bin/config/mkswap.c     12 Dec 2007 00:03:34 -0000      1.4
+++ usr.bin/config/mkswap.c     29 Nov 2008 00:43:47 -0000
@@ -133,14 +133,8 @@ mkoneswap(struct config *cf)
        /*
         * Emit the root file system.
         */
-       if (cf->cf_fstype == NULL)
-               strlcpy(specinfo, "NULL", sizeof(specinfo));
-       else {
-               snprintf(specinfo, sizeof(specinfo), "%s_mountroot",
-                   cf->cf_fstype);
-               fprintf(fp, "int %s(void);\n", specinfo);
-       }
-       fprintf(fp, "int (*mountroot)(void) = %s;\n", specinfo);
+       fprintf(fp, "const char *rootfstype = \"%s\";\n",
+               cf->cf_fstype ? cf->cf_fstype : "?");
 
        fflush(fp);
        if (ferror(fp))


Home | Main Index | Thread Index | Old Index