Bug 31009

Summary: Installing the current snapshot fails when calling MakeDevChunk().
Product: Base System Reporter: Hiroo Ono <hiroo>
Component: binAssignee: matusita
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Hiroo Ono 2001-10-03 15:50:00 UTC
	Installation of recent current snapshot fails.
	Editing of disklabel may fail from the same reason.

	installFilesystems() of usr.bin/sysinstall/install.c rev.1.307
	calls MakeDevChunk() of lib/libdisk/create_chunk.c rev.1.61,
	which then calls the function MakeDev() of the same file.
	Then, MakeDev() calls mknod(2) which fails when DEVFS is enabled.

Fix: 

(1) Checking DEVFS MIB using sysctl(3) in MakeDev() of the libdisk
	    and skip calling mknod(2) may be the best solution.
	(2) Or checking if DEVFS is enabled or not (as above) in
	    installFilesystems() of usr.bin/sysinstall can be an alternative.
	    But, it will not avoid similar problems if other programs call
	    MakeDevChunk() or MakeDev().
	(3) Disabling DEVFS in the install kernerl may be a quick but bad
	    solution. The bug will stay if one uses sysinstall in a system
	   with DEVFS enabled (e.g. when adding a HDD).
How-To-Repeat: 	Install the snapshot after October 1, 2001 or edit disklabels
	from the sysinstall. It will stop with the error message like:
	  mknod of /dev/rad0a1b returned failure status!
Comment 1 Hiroo Ono 2001-10-04 19:10:39 UTC
----Next_Part(Fri_Oct__5_02:54:40_2001_41)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I think the patch for lib/libdisk/create_chunk.c below solves the
problem. It checks the devfs MIB exists and return 1 if it exists.
As I failed to install FreeBSD-current due to this bug, I cannot test
if it works :-)

thanks to Masahide -mac- NODA, Hajimu UMEMOTO and Makoto `MAR' MATSUSHITA
for the advice.

----Next_Part(Fri_Oct__5_02:54:40_2001_41)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="create_chunk.c.diff"

*** create_chunk.c.orig	Fri Oct  5 02:07:06 2001
--- create_chunk.c	Fri Oct  5 02:31:10 2001
***************
*** 22,27 ****
--- 22,28 ----
  #include <sys/diskslice.h>
  #include <sys/types.h>
  #include <sys/stat.h>
+ #include <sys/sysctl.h>
  #include <grp.h>
  #include <paths.h>
  #include <pwd.h>
***************
*** 283,294 ****
--- 284,303 ----
      struct passwd *pwd;
      uid_t owner;
      gid_t group;
+     int mib[4];
+     size_t miblen;
  
      *buf2 = '\0';
+     miblen = sizeof(mib)/sizeof(mib[0]);
      if (isDebug())
  	msgDebug("MakeDev: Called with %s on path %s\n", p, path);
      if (!strcmp(p, "X"))
  	return 0;
+     if (!sysctlnametomib("vfs.devfs.generation", &mib, &miblen)) {
+ 	if (isDebug())
+ 	    msgDebug("MakeDev: No need to mknod(2) with DEVFS.\n");
+ 	return 1;
+     }
  
      if (!strncmp(p, "ad", 2))
  	cmaj = 116, p += 2;

----Next_Part(Fri_Oct__5_02:54:40_2001_41)----
Comment 2 Makoto Matsushita 2001-11-08 16:36:51 UTC
Hiroo-san's patch has a bug: if kernel does know about DEVFS, libdisk
doesn't do mknod(2) even if it's actually not DEVFS.  This causes that
current 5-current's sysinstall(8) fails to create filesystem while a
fresh installation procedure.

I've reported this bug (sysinstall fails to create filesystem) from
users of snapshots.jp.FreeBSD.org, and confirmed that hiroo-san's
patch is not an actual fix.

Jordan, would you please check my patch?  If you are OK, please commit
or I'll do.

P.S.: I've already discussed with hiroo-san about this patch.

-- -
Makoto `MAR' MATSUSHITA

Index: create_chunk.c
===================================================================
RCS file: /home/ncvs/src/lib/libdisk/create_chunk.c,v
retrieving revision 1.62
diff -u -r1.62 create_chunk.c
--- create_chunk.c	10 Oct 2001 07:46:04 -0000	1.62
+++ create_chunk.c	8 Nov 2001 16:23:17 -0000
@@ -17,10 +17,10 @@
 #include <ctype.h>
 #include <fcntl.h>
 #include <stdarg.h>
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/disklabel.h>
 #include <sys/diskslice.h>
-#include <sys/types.h>
+#include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/sysctl.h>
 #include <grp.h>
@@ -282,18 +282,22 @@
     char buf[BUFSIZ], buf2[BUFSIZ];
     struct group *grp;
     struct passwd *pwd;
+    struct statfs fs;
     uid_t owner;
     gid_t group;
-    int mib[4];
-    size_t miblen;
 
     *buf2 = '\0';
-    miblen = sizeof(mib)/sizeof(mib[0]);
     if (isDebug())
 	msgDebug("MakeDev: Called with %s on path %s\n", p, path);
     if (!strcmp(p, "X"))
 	return 0;
-    if (!sysctlnametomib("vfs.devfs.generation", &mib, &miblen)) {
+    if (statfs(path, &fs) != 0) {
+#ifdef DEBUG
+	warn("statfs(%s) failed\n", path);
+#endif
+	return 0;
+    }
+    if (strcmp(fs.f_fstypename, "devfs") == 0) {
 	if (isDebug())
 	    msgDebug("MakeDev: No need to mknod(2) with DEVFS.\n");
 	return 1;
Comment 3 Makoto Matsushita 2001-11-11 15:14:01 UTC
matusita> Hiroo-san's patch has a bug: if kernel does know about
matusita> DEVFS, libdisk doesn't do mknod(2) even if it's actually not
matusita> DEVFS.  This causes that current 5-current's sysinstall(8)
matusita> fails to create filesystem while a fresh installation
matusita> procedure.

I've made a small test, and this patch seems working as expected.  To
make more verification, I commited this patch.  I'll test with next
5-current SNAPSHOTs.

If it works fine, I'll close this PR.

-- -
Makoto `MAR' Matsushita
Comment 4 matusita freebsd_committer freebsd_triage 2001-11-11 23:48:09 UTC
State Changed
From-To: open->feedback

I've applied my patch as src/lib/libidisk/create_chunk.c rev 1.63, 
and 5.0-CURRENT-20011112-JPSNAP which was included a patch seems 
working.  Hiroo-san, would you please confirm that this bug is disappeared? 


Comment 5 matusita freebsd_committer freebsd_triage 2001-11-11 23:48:09 UTC
Responsible Changed
From-To: freebsd-bugs->matusita

I'll handle this to close this PR if problem is solved.
Comment 6 galen_sampson 2001-11-13 22:16:58 UTC
I have successfully been able to install -current with kern.flp and mfsroot.flp
downloaded from
ftp://current.freebsd.org/pub/FreeBSD/snapshots/i386/5.0-20011112-CURRENT.  The
same disks failed to install properly from 11-09, 11-10, and 11-11.  It seems
that the patch mentioned is working.

Galen

__________________________________________________
Do You Yahoo!?
Find the one for you at Yahoo! Personals
http://personals.yahoo.com
Comment 7 Makoto Matsushita 2001-11-14 05:45:52 UTC
galen_sampson>  I have successfully been able to install -current with
galen_sampson>  kern.flp and mfsroot.flp downloaded from
galen_sampson>  ftp://current.freebsd.org/pub/FreeBSD/snapshots/i386/5.0-20011112-CURRENT.

Glad to hear that, thank you.

-- -
Makoto `MAR' Matsushita
Comment 8 matusita freebsd_committer freebsd_triage 2001-11-14 12:39:48 UTC
State Changed
From-To: feedback->closed

src/lib/libdisk/create_chunk.c rev 1.63 fixes this problem. 
I and Galen Sampson <galen_sampson@yahoo.com> confirm that 
current SNAPSHOTs floppies do the right things.