]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/zfs_log.c
Project Quota on ZFS
[mirror_zfs.git] / module / zfs / zfs_log.c
index 69efb3c161323bbd33b72aecc28bf856554d0c48..ce7b84927e1e1c3efa99f36622299b179b7ef87f 100644 (file)
@@ -20,6 +20,7 @@
  */
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015 by Delphix. All rights reserved.
  */
 
 
@@ -165,8 +166,17 @@ zfs_log_xvattr(lr_attr_t *lrattr, xvattr_t *xvap)
                    XAT0_AV_MODIFIED;
        if (XVA_ISSET_REQ(xvap, XAT_CREATETIME))
                ZFS_TIME_ENCODE(&xoap->xoa_createtime, crtime);
-       if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
+       if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
+               ASSERT(!XVA_ISSET_REQ(xvap, XAT_PROJID));
+
                bcopy(xoap->xoa_av_scanstamp, scanstamp, AV_SCANSTAMP_SZ);
+       } else if (XVA_ISSET_REQ(xvap, XAT_PROJID)) {
+               /*
+                * XAT_PROJID and XAT_AV_SCANSTAMP will never be valid
+                * at the same time, so we can share the same space.
+                */
+               bcopy(&xoap->xoa_projid, scanstamp, sizeof (uint64_t));
+       }
        if (XVA_ISSET_REQ(xvap, XAT_REPARSE))
                *attrs |= (xoap->xoa_reparse == 0) ? 0 :
                    XAT0_REPARSE;
@@ -176,6 +186,9 @@ zfs_log_xvattr(lr_attr_t *lrattr, xvattr_t *xvap)
        if (XVA_ISSET_REQ(xvap, XAT_SPARSE))
                *attrs |= (xoap->xoa_sparse == 0) ? 0 :
                    XAT0_SPARSE;
+       if (XVA_ISSET_REQ(xvap, XAT_PROJINHERIT))
+               *attrs |= (xoap->xoa_projinherit == 0) ? 0 :
+                   XAT0_PROJINHERIT;
 }
 
 static void *
@@ -211,6 +224,34 @@ zfs_log_fuid_domains(zfs_fuid_info_t *fuidp, void *start)
        return (start);
 }
 
+/*
+ * If zp is an xattr node, check whether the xattr owner is unlinked.
+ * We don't want to log anything if the owner is unlinked.
+ */
+static int
+zfs_xattr_owner_unlinked(znode_t *zp)
+{
+       int unlinked = 0;
+       znode_t *dzp;
+       igrab(ZTOI(zp));
+       /*
+        * if zp is XATTR node, keep walking up via z_xattr_parent until we
+        * get the owner
+        */
+       while (zp->z_pflags & ZFS_XATTR) {
+               ASSERT3U(zp->z_xattr_parent, !=, 0);
+               if (zfs_zget(ZTOZSB(zp), zp->z_xattr_parent, &dzp) != 0) {
+                       unlinked = 1;
+                       break;
+               }
+               iput(ZTOI(zp));
+               zp = dzp;
+               unlinked = zp->z_unlinked;
+       }
+       iput(ZTOI(zp));
+       return (unlinked);
+}
+
 /*
  * Handles TX_CREATE, TX_CREATE_ATTR, TX_MKDIR, TX_MKDIR_ATTR and
  * TK_MKXATTR transactions.
@@ -247,7 +288,7 @@ zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
        size_t namesize = strlen(name) + 1;
        size_t fuidsz = 0;
 
-       if (zil_replaying(zilog, tx))
+       if (zil_replaying(zilog, tx) || zfs_xattr_owner_unlinked(dzp))
                return;
 
        /*
@@ -346,13 +387,13 @@ zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
  */
 void
 zfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
-       znode_t *dzp, char *name, uint64_t foid)
+    znode_t *dzp, char *name, uint64_t foid)
 {
        itx_t *itx;
        lr_remove_t *lr;
        size_t namesize = strlen(name) + 1;
 
-       if (zil_replaying(zilog, tx))
+       if (zil_replaying(zilog, tx) || zfs_xattr_owner_unlinked(dzp))
                return;
 
        itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
@@ -370,7 +411,7 @@ zfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
  */
 void
 zfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
-       znode_t *dzp, znode_t *zp, char *name)
+    znode_t *dzp, znode_t *zp, char *name)
 {
        itx_t *itx;
        lr_link_t *lr;
@@ -425,7 +466,7 @@ zfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
  */
 void
 zfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
-       znode_t *sdzp, char *sname, znode_t *tdzp, char *dname, znode_t *szp)
+    znode_t *sdzp, char *sname, znode_t *tdzp, char *dname, znode_t *szp)
 {
        itx_t *itx;
        lr_rename_t *lr;
@@ -455,26 +496,24 @@ long zfs_immediate_write_sz = 32768;
 
 void
 zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
-       znode_t *zp, offset_t off, ssize_t resid, int ioflag,
-       zil_callback_t callback, void *callback_data)
+    znode_t *zp, offset_t off, ssize_t resid, int ioflag,
+    zil_callback_t callback, void *callback_data)
 {
+       uint32_t blocksize = zp->z_blksz;
        itx_wr_state_t write_state;
-       boolean_t slogging;
        uintptr_t fsync_cnt;
-       ssize_t immediate_write_sz;
 
-       if (zil_replaying(zilog, tx) || zp->z_unlinked) {
+       if (zil_replaying(zilog, tx) || zp->z_unlinked ||
+           zfs_xattr_owner_unlinked(zp)) {
                if (callback != NULL)
                        callback(callback_data);
                return;
        }
 
-       immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT)
-           ? 0 : (ssize_t)zfs_immediate_write_sz;
-
-       slogging = spa_has_slogs(zilog->zl_spa) &&
-           (zilog->zl_logbias == ZFS_LOGBIAS_LATENCY);
-       if (resid > immediate_write_sz && !slogging && resid <= zp->z_blksz)
+       if (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT)
+               write_state = WR_INDIRECT;
+       else if (!spa_has_slogs(zilog->zl_spa) &&
+           resid >= zfs_immediate_write_sz)
                write_state = WR_INDIRECT;
        else if (ioflag & (FSYNC | FDSYNC))
                write_state = WR_COPIED;
@@ -488,30 +527,26 @@ zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
        while (resid) {
                itx_t *itx;
                lr_write_t *lr;
-               ssize_t len;
+               itx_wr_state_t wr_state = write_state;
+               ssize_t len = resid;
 
-               /*
-                * If the write would overflow the largest block then split it.
-                */
-               if (write_state != WR_INDIRECT && resid > ZIL_MAX_LOG_DATA)
-                       len = SPA_OLD_MAXBLOCKSIZE >> 1;
-               else
-                       len = resid;
+               if (wr_state == WR_COPIED && resid > ZIL_MAX_COPIED_DATA)
+                       wr_state = WR_NEED_COPY;
+               else if (wr_state == WR_INDIRECT)
+                       len = MIN(blocksize - P2PHASE(off, blocksize), resid);
 
                itx = zil_itx_create(txtype, sizeof (*lr) +
-                   (write_state == WR_COPIED ? len : 0));
+                   (wr_state == WR_COPIED ? len : 0));
                lr = (lr_write_t *)&itx->itx_lr;
-               if (write_state == WR_COPIED && dmu_read(ZTOZSB(zp)->z_os,
+               if (wr_state == WR_COPIED && dmu_read(ZTOZSB(zp)->z_os,
                    zp->z_id, off, len, lr + 1, DMU_READ_NO_PREFETCH) != 0) {
                        zil_itx_destroy(itx);
                        itx = zil_itx_create(txtype, sizeof (*lr));
                        lr = (lr_write_t *)&itx->itx_lr;
-                       write_state = WR_NEED_COPY;
+                       wr_state = WR_NEED_COPY;
                }
 
-               itx->itx_wr_state = write_state;
-               if (write_state == WR_NEED_COPY)
-                       itx->itx_sod += len;
+               itx->itx_wr_state = wr_state;
                lr->lr_foid = zp->z_id;
                lr->lr_offset = off;
                lr->lr_length = len;
@@ -538,12 +573,13 @@ zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
  */
 void
 zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
-       znode_t *zp, uint64_t off, uint64_t len)
+    znode_t *zp, uint64_t off, uint64_t len)
 {
        itx_t *itx;
        lr_truncate_t *lr;
 
-       if (zil_replaying(zilog, tx) || zp->z_unlinked)
+       if (zil_replaying(zilog, tx) || zp->z_unlinked ||
+           zfs_xattr_owner_unlinked(zp))
                return;
 
        itx = zil_itx_create(txtype, sizeof (*lr));