tech-kern archive

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

kern/46494 (cgd on 4K sector disk)



Hello,

   I tried reusing the secsize from getdisksize() in place of DEV_BSIZE.
After correcting for a resulting divide-by-zero, I get further, but only
by a fraction.

   The disk in question (model: WD7500AARX; "750GB") has a GPT with one
partition which spans as much as possible of the disk:

# gpt show sd0
      start       size  index  contents
          0          1         PMBR
          1          1         Pri GPT header
          2          4         Pri GPT table
          6  183143635      1  GPT part - NetBSD Cryptographic Disk
  183143641          4         Sec GPT table
  183143645          1         Sec GPT header

# dkctl sd0 listwedges
/dev/rsd0d: 1 wedge:
dk0: My Test, 183143635 blocks at 6, type: cgd

   cgd3 is configured on top of /dev/dk0.

   At this point I've been trying to take all kinds of random actions on
cgd3. For instance, creating a disklabel, creating a GPT, and using dd.

   What I can do now, with the attached patch (which I couldn't before),
is to create (as in 'write') a disklabel in cgd3.

   And dd appears to work fine on the cgd device.

   If I run "newfs -S 4096 /dev/cgd3a", I get:

--[newfs.out]------------------------
/dev/rcgd3a: 715404.8MB (183143635 sectors) block size 32768, fragment
size 4096
        using 966 cylinder groups of 741.25MB, 23720 blks, 47104 inodes.
wtfs: write error for sector 183143634: Invalid argument
-------------------------------------

-[dmesg.out]-------------------------
cgdopen(0x5130, 2)
getcgd_softc(0x5130): unit = 3
cgdioctl(0x5130, 2148557928, 0xfffffe80051e6870, 1, 0xfffffe807dca9ac0)
getcgd_softc(0x5130): unit = 3
cgdioctl(0x5130, 1074816127, 0xfffffe80051e6ad0, 1, 0xfffffe807dca9ac0)
getcgd_softc(0x5130): unit = 3
cgdioctl(0x5130, 1100506213, 0xfffffe807e2cfc80, 1, 0xfffffe807dca9ac0)
getcgd_softc(0x5130): unit = 3
cgdioctl(0x5130, 1087399034, 0xfffffe807d773d58, 1, 0xfffffe807dca9ac0)
getcgd_softc(0x5130): unit = 3
cgdioctl(0x5130, 1100506213, 0xfffffe807e2cfc80, 1, 0xfffffe807dca9ac0)
getcgd_softc(0x5130): unit = 3
cgdwrite(0x5130, 0xfffffe80051e6ae0, 16)
getcgd_softc(0x5130): unit = 3
physio: called: off=750156324864, resid=4096
getcgd_softc(0x5130): unit = 3
cgdstrategy(0xfffffe80799807b0): b_bcount = 4096
physio_done: error=22 at 750156324864 - 750156324864, blkno=1465149072,
bcount=4096, flags=0xc0000
physio_done: ps=0xfffffe807bd07780, error 0 -> 22, endoff
18446744073709551615 -> 750156324864
physio: done: off=750156328960, resid=4096
cgdclose(0x5130, 2)
getcgd_softc(0x5130): unit = 3
-------------------------------------

   I tried, with regards to "wtfs: write error for sector 183143634:
Invalid argument":

   # dd if=/dev/zero of=/dev/rcgd3d bs=4k count=1 seek=183143635
   1+0 records in
   1+0 records out
   4096 bytes transferred in 0.001 secs (4096000 bytes/sec)
   # echo $?
   0

   If dd on the cgd device appears to be working fine, the drive is
perfectly usable if I use it without a cgd device -- what should I be
looking at?

   For completeness, "gpt create cgd3" returns:

   gpt: unable to open device 'rcgd3d': Invalid argument


   Pointers are welcome.

-- 
Kind regards,
Jan Danielsson

Index: cgdvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/cgdvar.h,v
retrieving revision 1.14
diff -u -r1.14 cgdvar.h
--- cgdvar.h    12 Jan 2010 21:08:09 -0000      1.14
+++ cgdvar.h    31 May 2012 09:27:36 -0000
@@ -81,6 +81,7 @@
        struct cryptdata         sc_cdata;      /* crypto data */
        struct cryptfuncs       *sc_cfuncs;     /* encryption functions */
        struct simplelock        sc_slock;      /* our lock */
+       unsigned                 sc_secsize;    /* sector size */
 };
 #endif
 
Index: cgd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/cgd.c,v
retrieving revision 1.76
diff -u -r1.76 cgd.c
--- cgd.c       13 Nov 2011 23:03:24 -0000      1.76
+++ cgd.c       31 May 2012 09:27:36 -0000
@@ -301,7 +301,7 @@
         * buffers to be aligned to 32-bit boundaries.
         */
        if (bp->b_blkno < 0 ||
-           (bp->b_bcount % DEV_BSIZE) != 0 ||
+           (bp->b_bcount % cs->sc_secsize) != 0 ||
            ((uintptr_t)bp->b_data & 3) != 0) {
                bp->b_error = EINVAL;
                bp->b_resid = bp->b_bcount;
@@ -406,7 +406,7 @@
                        return -1;
                }
                cgd_cipher(cs, newaddr, addr, bp->b_bcount, bn,
-                   DEV_BSIZE, CGD_CIPHER_ENCRYPT);
+                   cs->sc_secsize, CGD_CIPHER_ENCRYPT);
        }
 
        nbp->b_data = newaddr;
@@ -461,7 +461,7 @@
 
        if (nbp->b_flags & B_READ)
                cgd_cipher(cs, obp->b_data, obp->b_data, obp->b_bcount,
-                   nbp->b_blkno, DEV_BSIZE, CGD_CIPHER_DECRYPT);
+                   nbp->b_blkno, cs->sc_secsize, CGD_CIPHER_DECRYPT);
 
        /* If we allocated memory, free it now... */
        if (nbp->b_data != obp->b_data)
@@ -739,7 +739,6 @@
        int     ret;
        char    *tmppath;
        uint64_t psize;
-       unsigned secsize;
 
        cs->sc_dksc.sc_size = 0;
        cs->sc_tvn = vp;
@@ -760,7 +759,7 @@
 
        cs->sc_tdev = va.va_rdev;
 
-       if ((ret = getdisksize(vp, &psize, &secsize)) != 0)
+       if ((ret = getdisksize(vp, &psize, &cs->sc_secsize)) != 0)
                goto bail;
 
        if (psize == 0) {
@@ -777,9 +776,9 @@
         *     geometry that we discover from the device.
         */
        pdg = &cs->sc_dksc.sc_geom;
-       pdg->pdg_secsize = DEV_BSIZE;
+       pdg->pdg_secsize = cs->sc_secsize;
        pdg->pdg_ntracks = 1;
-       pdg->pdg_nsectors = 1024 * (1024 / pdg->pdg_secsize);
+       pdg->pdg_nsectors = (1024 * 1024) / pdg->pdg_secsize;
        pdg->pdg_ncylinders = cs->sc_dksc.sc_size / pdg->pdg_nsectors;
 
 bail:


Home | Main Index | Thread Index | Old Index