Print this page
3580 Want zvols to return volblocksize when queried for physical block size
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>


1610 
1611         itx = zil_itx_create(TX_TRUNCATE, sizeof (*lr));
1612         lr = (lr_truncate_t *)&itx->itx_lr;
1613         lr->lr_foid = ZVOL_OBJ;
1614         lr->lr_offset = off;
1615         lr->lr_length = len;
1616 
1617         itx->itx_sync = sync;
1618         zil_itx_assign(zilog, itx, tx);
1619 }
1620 
1621 /*
1622  * Dirtbag ioctls to support mkfs(1M) for UFS filesystems.  See dkio(7I).
1623  * Also a dirtbag dkio ioctl for unmap/free-block functionality.
1624  */
1625 /*ARGSUSED*/
1626 int
1627 zvol_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp)
1628 {
1629         zvol_state_t *zv;
1630         struct dk_cinfo dki;
1631         struct dk_minfo dkm;
1632         struct dk_callback *dkc;
1633         int error = 0;
1634         rl_t *rl;
1635 
1636         mutex_enter(&zfsdev_state_lock);
1637 
1638         zv = zfsdev_get_soft_state(getminor(dev), ZSST_ZVOL);
1639 
1640         if (zv == NULL) {
1641                 mutex_exit(&zfsdev_state_lock);
1642                 return (SET_ERROR(ENXIO));
1643         }
1644         ASSERT(zv->zv_total_opens > 0);
1645 
1646         switch (cmd) {
1647 
1648         case DKIOCINFO:



1649                 bzero(&dki, sizeof (dki));
1650                 (void) strcpy(dki.dki_cname, "zvol");
1651                 (void) strcpy(dki.dki_dname, "zvol");
1652                 dki.dki_ctype = DKC_UNKNOWN;
1653                 dki.dki_unit = getminor(dev);
1654                 dki.dki_maxtransfer = 1 << (SPA_MAXBLOCKSHIFT - zv->zv_min_bs);
1655                 mutex_exit(&zfsdev_state_lock);
1656                 if (ddi_copyout(&dki, (void *)arg, sizeof (dki), flag))
1657                         error = SET_ERROR(EFAULT);
1658                 return (error);

1659 
1660         case DKIOCGMEDIAINFO:



1661                 bzero(&dkm, sizeof (dkm));
1662                 dkm.dki_lbsize = 1U << zv->zv_min_bs;
1663                 dkm.dki_capacity = zv->zv_volsize >> zv->zv_min_bs;
1664                 dkm.dki_media_type = DK_UNKNOWN;
1665                 mutex_exit(&zfsdev_state_lock);
1666                 if (ddi_copyout(&dkm, (void *)arg, sizeof (dkm), flag))
1667                         error = SET_ERROR(EFAULT);
1668                 return (error);

1669 















1670         case DKIOCGETEFI:
1671                 {
1672                         uint64_t vs = zv->zv_volsize;
1673                         uint8_t bs = zv->zv_min_bs;
1674 
1675                         mutex_exit(&zfsdev_state_lock);
1676                         error = zvol_getefi((void *)arg, flag, vs, bs);
1677                         return (error);
1678                 }
1679 
1680         case DKIOCFLUSHWRITECACHE:
1681                 dkc = (struct dk_callback *)arg;
1682                 mutex_exit(&zfsdev_state_lock);
1683                 zil_commit(zv->zv_zilog, ZVOL_OBJ);
1684                 if ((flag & FKIOCTL) && dkc != NULL && dkc->dkc_callback) {
1685                         (*dkc->dkc_callback)(dkc->dkc_cookie, error);
1686                         error = 0;
1687                 }
1688                 return (error);
1689 




1610 
1611         itx = zil_itx_create(TX_TRUNCATE, sizeof (*lr));
1612         lr = (lr_truncate_t *)&itx->itx_lr;
1613         lr->lr_foid = ZVOL_OBJ;
1614         lr->lr_offset = off;
1615         lr->lr_length = len;
1616 
1617         itx->itx_sync = sync;
1618         zil_itx_assign(zilog, itx, tx);
1619 }
1620 
1621 /*
1622  * Dirtbag ioctls to support mkfs(1M) for UFS filesystems.  See dkio(7I).
1623  * Also a dirtbag dkio ioctl for unmap/free-block functionality.
1624  */
1625 /*ARGSUSED*/
1626 int
1627 zvol_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp)
1628 {
1629         zvol_state_t *zv;


1630         struct dk_callback *dkc;
1631         int error = 0;
1632         rl_t *rl;
1633 
1634         mutex_enter(&zfsdev_state_lock);
1635 
1636         zv = zfsdev_get_soft_state(getminor(dev), ZSST_ZVOL);
1637 
1638         if (zv == NULL) {
1639                 mutex_exit(&zfsdev_state_lock);
1640                 return (SET_ERROR(ENXIO));
1641         }
1642         ASSERT(zv->zv_total_opens > 0);
1643 
1644         switch (cmd) {
1645 
1646         case DKIOCINFO:
1647         {
1648                 struct dk_cinfo dki;
1649 
1650                 bzero(&dki, sizeof (dki));
1651                 (void) strcpy(dki.dki_cname, "zvol");
1652                 (void) strcpy(dki.dki_dname, "zvol");
1653                 dki.dki_ctype = DKC_UNKNOWN;
1654                 dki.dki_unit = getminor(dev);
1655                 dki.dki_maxtransfer = 1 << (SPA_MAXBLOCKSHIFT - zv->zv_min_bs);
1656                 mutex_exit(&zfsdev_state_lock);
1657                 if (ddi_copyout(&dki, (void *)arg, sizeof (dki), flag))
1658                         error = SET_ERROR(EFAULT);
1659                 return (error);
1660         }
1661 
1662         case DKIOCGMEDIAINFO:
1663         {
1664                 struct dk_minfo dkm;
1665 
1666                 bzero(&dkm, sizeof (dkm));
1667                 dkm.dki_lbsize = 1U << zv->zv_min_bs;
1668                 dkm.dki_capacity = zv->zv_volsize >> zv->zv_min_bs;
1669                 dkm.dki_media_type = DK_UNKNOWN;
1670                 mutex_exit(&zfsdev_state_lock);
1671                 if (ddi_copyout(&dkm, (void *)arg, sizeof (dkm), flag))
1672                         error = SET_ERROR(EFAULT);
1673                 return (error);
1674         }
1675 
1676         case DKIOCGMEDIAINFOEXT:
1677         {
1678                 struct dk_minfo_ext dkmext;
1679 
1680                 bzero(&dkmext, sizeof (dkmext));
1681                 dkmext.dki_lbsize = 1U << zv->zv_min_bs;
1682                 dkmext.dki_pbsize = zv->zv_volblocksize;
1683                 dkmext.dki_capacity = zv->zv_volsize >> zv->zv_min_bs;
1684                 dkmext.dki_media_type = DK_UNKNOWN;
1685                 mutex_exit(&zfsdev_state_lock);
1686                 if (ddi_copyout(&dkmext, (void *)arg, sizeof (dkmext), flag))
1687                         error = SET_ERROR(EFAULT);
1688                 return (error);
1689         }
1690 
1691         case DKIOCGETEFI:
1692         {
1693                 uint64_t vs = zv->zv_volsize;
1694                 uint8_t bs = zv->zv_min_bs;
1695 
1696                 mutex_exit(&zfsdev_state_lock);
1697                 error = zvol_getefi((void *)arg, flag, vs, bs);
1698                 return (error);
1699         }
1700 
1701         case DKIOCFLUSHWRITECACHE:
1702                 dkc = (struct dk_callback *)arg;
1703                 mutex_exit(&zfsdev_state_lock);
1704                 zil_commit(zv->zv_zilog, ZVOL_OBJ);
1705                 if ((flag & FKIOCTL) && dkc != NULL && dkc->dkc_callback) {
1706                         (*dkc->dkc_callback)(dkc->dkc_cookie, error);
1707                         error = 0;
1708                 }
1709                 return (error);
1710