NetBSD-Bugs archive

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

Re: kern/48849: root mirror raid fails on shutdown



The following reply was made to PR kern/48849; it has been noted by GNATS.

From: "J. Hannken-Illjes" <hannken%eis.cs.tu-bs.de@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: kern/48849: root mirror raid fails on shutdown
Date: Wed, 4 Jun 2014 11:18:40 +0200

 --Apple-Mail=_75D36A34-10A6-4B2A-A8E7-2501FAD95608
 Content-Transfer-Encoding: 7bit
 Content-Type: text/plain;
        charset=us-ascii
 
 Please try the attached diff.  It will
 
  Change dk_lookup() to return an anonymous vnode not associated with
  any file system.  Change all consumers of dk_lookup() to get the
  device from "v_rdev" instead of VOP_GETATTR() as specfs does not
  support VOP_GETATTR().  Devices obtained with dk_lookup() will no
  longer disappear on forced unmounts.
 
 Please make sure you have a full backup as this diff changes
 ccd, cgd, dm/lvm and raid, not all covered by anita tests.
 
 --
 J. Hannken-Illjes - hannken%eis.cs.tu-bs.de@localhost - TU Braunschweig 
(Germany)
 
 
 --Apple-Mail=_75D36A34-10A6-4B2A-A8E7-2501FAD95608
 Content-Disposition: attachment;
        filename=patch.diff
 Content-Type: application/octet-stream;
        name="patch.diff"
 Content-Transfer-Encoding: 7bit
 
 Index: sys/dev/ccd.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/ccd.c,v
 retrieving revision 1.148
 diff -p -u -4 -r1.148 ccd.c
 --- sys/dev/ccd.c      6 Apr 2014 00:56:39 -0000       1.148
 +++ sys/dev/ccd.c      4 Jun 2014 08:39:37 -0000
 @@ -120,8 +120,10 @@ __KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.14
  
  #include <dev/ccdvar.h>
  #include <dev/dkvar.h>
  
 +#include <miscfs/specfs/specdev.h> /* for v_rdev */
 +
  #if defined(CCDDEBUG) && !defined(DEBUG)
  #define DEBUG
  #endif
  
 @@ -291,9 +293,8 @@ ccdinit(struct ccd_softc *cs, char **cpa
      struct lwp *l)
  {
        struct ccdcinfo *ci = NULL;
        int ix;
 -      struct vattr va;
        struct ccdgeom *ccg = &cs->sc_geom;
        char *tmppath;
        int error, path_alloced;
        uint64_t psize, minsize;
 @@ -343,21 +344,9 @@ ccdinit(struct ccd_softc *cs, char **cpa
  
                /*
                 * XXX: Cache the component's dev_t.
                 */
 -              vn_lock(vpp[ix], LK_SHARED | LK_RETRY);
 -              error = VOP_GETATTR(vpp[ix], &va, l->l_cred);
 -              VOP_UNLOCK(vpp[ix]);
 -              if (error != 0) {
 -#ifdef DEBUG
 -                      if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
 -                              printf("%s: %s: getattr failed %s = %d\n",
 -                                  cs->sc_xname, ci->ci_path,
 -                                  "error", error);
 -#endif
 -                      goto out;
 -              }
 -              ci->ci_dev = va.va_rdev;
 +              ci->ci_dev = vpp[ix]->v_rdev;
  
                /*
                 * Get partition information for the component.
                 */
 Index: sys/dev/cgd.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/cgd.c,v
 retrieving revision 1.87
 diff -p -u -4 -r1.87 cgd.c
 --- sys/dev/cgd.c      25 May 2014 19:23:49 -0000      1.87
 +++ sys/dev/cgd.c      4 Jun 2014 08:39:37 -0000
 @@ -54,8 +54,10 @@ __KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.87
  
  #include <dev/dkvar.h>
  #include <dev/cgdvar.h>
  
 +#include <miscfs/specfs/specdev.h> /* for v_rdev */
 +
  /* Entry Point Functions */
  
  void  cgdattach(int);
  
 @@ -808,9 +810,8 @@ static int
  cgdinit(struct cgd_softc *cs, const char *cpath, struct vnode *vp,
        struct lwp *l)
  {
        struct  disk_geom *dg;
 -      struct  vattr va;
        int     ret;
        char    *tmppath;
        uint64_t psize;
        unsigned secsize;
 @@ -825,15 +826,9 @@ cgdinit(struct cgd_softc *cs, const char
                goto bail;
        cs->sc_tpath = malloc(cs->sc_tpathlen, M_DEVBUF, M_WAITOK);
        memcpy(cs->sc_tpath, tmppath, cs->sc_tpathlen);
  
 -      vn_lock(vp, LK_SHARED | LK_RETRY);
 -      ret = VOP_GETATTR(vp, &va, l->l_cred);
 -      VOP_UNLOCK(vp);
 -      if (ret != 0)
 -              goto bail;
 -
 -      cs->sc_tdev = va.va_rdev;
 +      cs->sc_tdev = vp->v_rdev;
  
        if ((ret = getdisksize(vp, &psize, &secsize)) != 0)
                goto bail;
  
 Index: sys/dev/dksubr.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/dksubr.c,v
 retrieving revision 1.50
 diff -p -u -4 -r1.50 dksubr.c
 --- sys/dev/dksubr.c   25 May 2014 19:23:49 -0000      1.50
 +++ sys/dev/dksubr.c   4 Jun 2014 08:39:37 -0000
 @@ -47,8 +47,9 @@ __KERNEL_RCSID(0, "$NetBSD: dksubr.c,v 1
  #include <sys/namei.h>
  #include <sys/module.h>
  
  #include <dev/dkvar.h>
 +#include <miscfs/specfs/specdev.h> /* for v_rdev */
  
  int   dkdebug = 0;
  
  #ifdef DEBUG
 @@ -620,9 +621,8 @@ int
  dk_lookup(struct pathbuf *pb, struct lwp *l, struct vnode **vpp)
  {
        struct nameidata nd;
        struct vnode *vp;
 -      struct vattr va;
        int     error;
  
        if (l == NULL)
                return ESRCH;   /* Is ESRCH the best choice? */
 @@ -634,24 +634,31 @@ dk_lookup(struct pathbuf *pb, struct lwp
                return error;
        }
  
        vp = nd.ni_vp;
 -      if ((error = VOP_GETATTR(vp, &va, l->l_cred)) != 0) {
 -              DPRINTF((DKDB_FOLLOW|DKDB_INIT),
 -                  ("dk_lookup: getattr error = %d\n", error));
 +      if (vp->v_type != VBLK) {
 +              error = ENOTBLK;
                goto out;
        }
  
 -      /* XXX: eventually we should handle VREG, too. */
 -      if (va.va_type != VBLK) {
 -              error = ENOTBLK;
 +      /* Reopen as anonymous vnode to protect against forced unmount. */
 +      if ((error = bdevvp(vp->v_rdev, vpp)) != 0)
                goto out;
 +      VOP_UNLOCK(vp);
 +      if ((error = vn_close(vp, FREAD | FWRITE, l->l_cred)) != 0) {
 +              vrele(*vpp);
 +              return error;
 +      }
 +      if ((error = VOP_OPEN(*vpp, FREAD | FWRITE, l->l_cred)) != 0) {
 +              vrele(*vpp);
 +              return error;
        }
 +      mutex_enter((*vpp)->v_interlock);
 +      (*vpp)->v_writecount++;
 +      mutex_exit((*vpp)->v_interlock);
  
 -      IFDEBUG(DKDB_VNODE, vprint("dk_lookup: vnode info", vp));
 +      IFDEBUG(DKDB_VNODE, vprint("dk_lookup: vnode info", *vpp));
  
 -      VOP_UNLOCK(vp);
 -      *vpp = vp;
        return 0;
  out:
        VOP_UNLOCK(vp);
        (void) vn_close(vp, FREAD | FWRITE, l->l_cred);
 Index: sys/dev/dm/dm.h
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/dm/dm.h,v
 retrieving revision 1.25
 diff -p -u -4 -r1.25 dm.h
 --- sys/dev/dm/dm.h    9 Dec 2013 09:35:16 -0000       1.25
 +++ sys/dev/dm/dm.h    4 Jun 2014 08:39:38 -0000
 @@ -48,8 +48,10 @@
  #include <sys/device.h>
  #include <sys/disk.h>
  #include <sys/disklabel.h>
  
 +#include <miscfs/specfs/specdev.h> /* for v_rdev */
 +
  #include <prop/proplib.h>
  
  #define DM_MAX_TYPE_NAME 16
  #define DM_NAME_LEN 128
 Index: sys/dev/dm/dm_target_linear.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/dm/dm_target_linear.c,v
 retrieving revision 1.13
 diff -p -u -4 -r1.13 dm_target_linear.c
 --- sys/dev/dm/dm_target_linear.c      14 Oct 2011 09:23:30 -0000      1.13
 +++ sys/dev/dm/dm_target_linear.c      4 Jun 2014 08:39:38 -0000
 @@ -191,24 +191,16 @@ dm_target_linear_destroy(dm_table_entry_
  int
  dm_target_linear_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
  {
        dm_target_linear_config_t *tlc;
 -      struct vattr va;
 -
 -      int error;
  
        if (table_en->target_config == NULL)
                return ENOENT;
  
        tlc = table_en->target_config;
  
 -      vn_lock(tlc->pdev->pdev_vnode, LK_SHARED | LK_RETRY);
 -      error = VOP_GETATTR(tlc->pdev->pdev_vnode, &va, curlwp->l_cred);
 -      VOP_UNLOCK(tlc->pdev->pdev_vnode);
 -      if (error != 0)
 -              return error;
 -
 -      prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
 +      prop_array_add_uint64(prop_array,
 +          (uint64_t) tlc->pdev->pdev_vnode->v_rdev);
  
        return 0;
  }
  /*
 Index: sys/dev/dm/dm_target_snapshot.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/dm/dm_target_snapshot.c,v
 retrieving revision 1.15
 diff -p -u -4 -r1.15 dm_target_snapshot.c
 --- sys/dev/dm/dm_target_snapshot.c    14 Oct 2011 09:23:30 -0000      1.15
 +++ sys/dev/dm/dm_target_snapshot.c    4 Jun 2014 08:39:38 -0000
 @@ -347,35 +347,20 @@ int
  dm_target_snapshot_deps(dm_table_entry_t * table_en,
      prop_array_t prop_array)
  {
        dm_target_snapshot_config_t *tsc;
 -      struct vattr va;
 -
 -      int error;
  
        if (table_en->target_config == NULL)
                return 0;
  
        tsc = table_en->target_config;
  
 -      vn_lock(tsc->tsc_snap_dev->pdev_vnode, LK_SHARED | LK_RETRY);
 -      error = VOP_GETATTR(tsc->tsc_snap_dev->pdev_vnode, &va, curlwp->l_cred);
 -      VOP_UNLOCK(tsc->tsc_snap_dev->pdev_vnode);
 -      if (error != 0)
 -              return error;
 -
 -      prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
 +      prop_array_add_uint64(prop_array,
 +          (uint64_t) tsc->tsc_snap_dev->pdev_vnode->v_rdev);
  
        if (tsc->tsc_persistent_dev) {
 -
 -              vn_lock(tsc->tsc_cow_dev->pdev_vnode, LK_SHARED | LK_RETRY);
 -              error = VOP_GETATTR(tsc->tsc_cow_dev->pdev_vnode, &va,
 -                  curlwp->l_cred);
 -              VOP_UNLOCK(tsc->tsc_cow_dev->pdev_vnode);
 -              if (error != 0)
 -                      return error;
 -
 -              prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
 +              prop_array_add_uint64(prop_array,
 +                  (uint64_t) tsc->tsc_cow_dev->pdev_vnode->v_rdev);
  
        }
        return 0;
  }
 Index: sys/dev/dm/dm_target_stripe.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/dm/dm_target_stripe.c,v
 retrieving revision 1.18
 diff -p -u -4 -r1.18 dm_target_stripe.c
 --- sys/dev/dm/dm_target_stripe.c      7 Aug 2012 16:11:11 -0000       1.18
 +++ sys/dev/dm/dm_target_stripe.c      4 Jun 2014 08:39:38 -0000
 @@ -318,25 +318,17 @@ int
  dm_target_stripe_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
  {
        dm_target_stripe_config_t *tsc;
        dm_target_linear_config_t *tlc;
 -      struct vattr va;
 -
 -      int error;
  
        if (table_en->target_config == NULL)
                return ENOENT;
  
        tsc = table_en->target_config;
  
        TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) {
 -              vn_lock(tlc->pdev->pdev_vnode, LK_SHARED | LK_RETRY);
 -              error = VOP_GETATTR(tlc->pdev->pdev_vnode, &va, curlwp->l_cred);
 -              VOP_UNLOCK(tlc->pdev->pdev_vnode);
 -              if (error != 0)
 -                      return error;
 -
 -              prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
 +              prop_array_add_uint64(prop_array,
 +                  (uint64_t) tlc->pdev->pdev_vnode->v_rdev);
        }
  
        return 0;
  }
 Index: sys/dev/raidframe/rf_copyback.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/raidframe/rf_copyback.c,v
 retrieving revision 1.49
 diff -p -u -4 -r1.49 rf_copyback.c
 --- sys/dev/raidframe/rf_copyback.c    14 Oct 2011 09:23:30 -0000      1.49
 +++ sys/dev/raidframe/rf_copyback.c    4 Jun 2014 08:39:39 -0000
 @@ -82,8 +82,10 @@ rf_ConfigureCopyback(RF_ShutdownList_t *
  #include <sys/fcntl.h>
  #include <sys/vnode.h>
  #include <sys/namei.h> /* for pathbuf */
  
 +#include <miscfs/specfs/specdev.h> /* for v_rdev */
 +
  /* do a complete copyback */
  void
  rf_CopybackReconstructedData(RF_Raid_t *raidPtr)
  {
 @@ -95,9 +97,8 @@ rf_CopybackReconstructedData(RF_Raid_t *
        char   *databuf;
  
        struct pathbuf *dev_pb;
        struct vnode *vp;
 -      struct vattr va;
  
        int ac;
  
        fcol = 0;
 @@ -159,22 +160,17 @@ rf_CopybackReconstructedData(RF_Raid_t *
  
                /* Ok, so we can at least do a lookup... How about actually
                 * getting a vp for it? */
  
 -              vn_lock(vp, LK_SHARED | LK_RETRY);
 -              retcode = VOP_GETATTR(vp, &va, curlwp->l_cred);
 -              VOP_UNLOCK(vp);
 -              if (retcode != 0)
 -                      return;
                retcode = rf_getdisksize(vp, &raidPtr->Disks[fcol]);
                if (retcode) {
                        return;
                }
  
                raidPtr->raid_cinfo[fcol].ci_vp = vp;
 -              raidPtr->raid_cinfo[fcol].ci_dev = va.va_rdev;
 +              raidPtr->raid_cinfo[fcol].ci_dev = vp->v_rdev;
  
 -              raidPtr->Disks[fcol].dev = va.va_rdev;  /* XXX or the above? */
 +              raidPtr->Disks[fcol].dev = vp->v_rdev;  /* XXX or the above? */
  
                /* we allow the user to specify that only a fraction of the
                 * disks should be used this is just for debug:  it speeds up
                 * the parity scan */
 Index: sys/dev/raidframe/rf_disks.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/raidframe/rf_disks.c,v
 retrieving revision 1.85
 diff -p -u -4 -r1.85 rf_disks.c
 --- sys/dev/raidframe/rf_disks.c       25 Mar 2014 16:19:14 -0000      1.85
 +++ sys/dev/raidframe/rf_disks.c       4 Jun 2014 08:39:39 -0000
 @@ -79,8 +79,9 @@ __KERNEL_RCSID(0, "$NetBSD: rf_disks.c,v
  #include <sys/fcntl.h>
  #include <sys/vnode.h>
  #include <sys/namei.h> /* for pathbuf */
  #include <sys/kauth.h>
 +#include <miscfs/specfs/specdev.h> /* for v_rdev */
  
  static int rf_AllocDiskStructures(RF_Raid_t *, RF_Config_t *);
  static void rf_print_label_status( RF_Raid_t *, int, char *,
                                  RF_ComponentLabel_t *);
 @@ -575,9 +576,8 @@ rf_ConfigureDisk(RF_Raid_t *raidPtr, cha
  {
        char   *p;
        struct pathbuf *pb;
        struct vnode *vp;
 -      struct vattr va;
        int     error;
  
        p = rf_find_non_white(bf);
        if (p[strlen(p) - 1] == '\n') {
 @@ -630,20 +630,14 @@ rf_ConfigureDisk(RF_Raid_t *raidPtr, cha
        if (raidPtr->bytesPerSector == 0)
                raidPtr->bytesPerSector = diskPtr->blockSize;
  
        if (diskPtr->status == rf_ds_optimal) {
 -              vn_lock(vp, LK_SHARED | LK_RETRY);
 -              error = VOP_GETATTR(vp, &va, curlwp->l_cred);
 -              VOP_UNLOCK(vp);
 -              if (error != 0)
 -                      return (error);
 -
                raidPtr->raid_cinfo[col].ci_vp = vp;
 -              raidPtr->raid_cinfo[col].ci_dev = va.va_rdev;
 +              raidPtr->raid_cinfo[col].ci_dev = vp->v_rdev;
  
                /* This component was not automatically configured */
                diskPtr->auto_configured = 0;
 -              diskPtr->dev = va.va_rdev;
 +              diskPtr->dev = vp->v_rdev;
  
                /* we allow the user to specify that only a fraction of the
                 * disks should be used this is just for debug:  it speeds up
                 * the parity scan */
 Index: sys/dev/raidframe/rf_reconstruct.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/raidframe/rf_reconstruct.c,v
 retrieving revision 1.119
 diff -p -u -4 -r1.119 rf_reconstruct.c
 --- sys/dev/raidframe/rf_reconstruct.c 6 Mar 2013 11:38:15 -0000       1.119
 +++ sys/dev/raidframe/rf_reconstruct.c 4 Jun 2014 08:39:39 -0000
 @@ -46,8 +46,10 @@ __KERNEL_RCSID(0, "$NetBSD: rf_reconstru
  #include <sys/vnode.h>
  #include <sys/namei.h> /* for pathbuf */
  #include <dev/raidframe/raidframevar.h>
  
 +#include <miscfs/specfs/specdev.h> /* for v_rdev */
 +
  #include "rf_raid.h"
  #include "rf_reconutil.h"
  #include "rf_revent.h"
  #include "rf_reconbuffer.h"
 @@ -351,9 +353,8 @@ rf_ReconstructInPlace(RF_Raid_t *raidPtr
        uint64_t numsec;
        unsigned int secsize;
        struct pathbuf *pb;
        struct vnode *vp;
 -      struct vattr va;
        int retcode;
        int ac;
  
        rf_lock_mutex2(raidPtr->mutex);
 @@ -455,20 +456,8 @@ rf_ReconstructInPlace(RF_Raid_t *raidPtr
  
        /* Ok, so we can at least do a lookup...
           How about actually getting a vp for it? */
  
 -      vn_lock(vp, LK_SHARED | LK_RETRY);
 -      retcode = VOP_GETATTR(vp, &va, curlwp->l_cred);
 -      VOP_UNLOCK(vp);
 -      if (retcode != 0) {
 -              vn_close(vp, FREAD | FWRITE, kauth_cred_get());
 -              rf_lock_mutex2(raidPtr->mutex);
 -              raidPtr->reconInProgress--;
 -              rf_signal_cond2(raidPtr->waitForReconCond);
 -              rf_unlock_mutex2(raidPtr->mutex);
 -              return(retcode);
 -      }
 -
        retcode = getdisksize(vp, &numsec, &secsize);
        if (retcode) {
                vn_close(vp, FREAD | FWRITE, kauth_cred_get());
                rf_lock_mutex2(raidPtr->mutex);
 @@ -481,11 +470,11 @@ rf_ReconstructInPlace(RF_Raid_t *raidPtr
        raidPtr->Disks[col].blockSize = secsize;
        raidPtr->Disks[col].numBlocks = numsec - rf_protectedSectors;
  
        raidPtr->raid_cinfo[col].ci_vp = vp;
 -      raidPtr->raid_cinfo[col].ci_dev = va.va_rdev;
 +      raidPtr->raid_cinfo[col].ci_dev = vp->v_rdev;
  
 -      raidPtr->Disks[col].dev = va.va_rdev;
 +      raidPtr->Disks[col].dev = vp->v_rdev;
  
        /* we allow the user to specify that only a fraction
           of the disks should be used this is just for debug:
           it speeds up * the parity scan */
 
 --Apple-Mail=_75D36A34-10A6-4B2A-A8E7-2501FAD95608--
 


Home | Main Index | Thread Index | Old Index