On Tue, Nov 26, 2002 at 09:00:37PM +1100, Bruce Evans wrote the words in effect of:
> On 26 Nov 2002, Vladimir B.  Grebenschikov wrote:
> 
> > # mdconfig  -a -t vnode ./bootimg.bin
> > mdconfig: ioctl(/dev/mdctl): Bad address
> 
> This should be ... "-t vnode -f ./bootimg.bin".
> 
> The bug is just low quality option parsing.  ./bootimg.bin is garbage
> when it is not preceded by -f, and garbage args are silently ignored.
> A "-f file" is required to specify the vnode for "-t vnode" but neither
> the man page synopsis nor the usage message are detailed enough to
> say this.  When no file arg is specified, the file arg is NULL and
> this causes the "Bad address" error.

There is also a problem, when the md(4) driver is passed a 0 byte file,
i.e. mdconfig -a -t -vnode -f /tmp/mdimage.zero.  It simply hangs the
process in the `mddestroy' state, making it unkillable.

David Wolfskill tested a patch, which I made.  It could be a _possible_
fix to the problem.   When a 0 byte file is found, by mdcreate_vnode()
it passes up an EINVAL.

I used the stat structure, and the vn_stat() routine to get the information,
although I am not sure if that is the best/sane way of doing it.  The URL for
the patch is: http://www.unixdaemons.com/~hiten/work/diffs/md.c.patch

Cheers.

-- 
Hiten Pandya ([EMAIL PROTECTED], [EMAIL PROTECTED])
http://www.unixdaemons.com/~hiten/
Index: md.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/md/md.c,v
retrieving revision 1.74
diff -u -r1.74 md.c
--- md.c        2002/10/21 20:08:28     1.74
+++ md.c        2002/11/24 23:43:40
@@ -79,6 +79,7 @@
 #include <sys/stdint.h>
 #include <sys/sysctl.h>
 #include <sys/vnode.h>
+#include <sys/stat.h>
 
 #include <vm/vm.h>
 #include <vm/vm_object.h>
@@ -807,6 +808,7 @@
        struct md_s *sc;
        struct vattr vattr;
        struct nameidata nd;
+       struct stat sb;
        int error, flags;
 
        flags = FREAD|FWRITE;
@@ -828,6 +830,13 @@
                (void) vn_close(nd.ni_vp, flags, td->td_ucred, td);
                return (error ? error : EINVAL);
        }
+
+       error = vn_stat(nd.ni_vp, &sb, td->td_ucred, NOCRED, td);
+       if (error)
+               return (error);
+       if (sb.st_size == 0)
+               return (EINVAL);
+       
        VOP_UNLOCK(nd.ni_vp, 0, td);
 
        if (mdio->md_options & MD_AUTOUNIT) {

Reply via email to