Wrap with HAVE_XVATTR
[zfs.git] / module / zfs / zfs_log.c
index bf9f37b..5cdbb6c 100644 (file)
  * CDDL HEADER END
  */
 /*
- * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
+
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/systm.h>
 int
 zfs_log_create_txtype(zil_create_t type, vsecattr_t *vsecp, vattr_t *vap)
 {
+#ifdef HAVE_XVATTR
        int isxvattr = (vap->va_mask & AT_XVATTR);
+#else
+       int isxvattr = 0;
+#endif /* HAVE_XVATTR */
        switch (type) {
        case Z_FILE:
                if (vsecp == NULL && !isxvattr)
@@ -97,6 +101,7 @@ zfs_log_create_txtype(zil_create_t type, vsecattr_t *vsecp, vattr_t *vap)
        return (TX_MAX_TYPE);
 }
 
+#ifdef HAVE_XVATTR
 /*
  * build up the log data necessary for logging xvattr_t
  * First lr_attr_t is initialized.  following the lr_attr_t
@@ -170,6 +175,12 @@ zfs_log_xvattr(lr_attr_t *lrattr, xvattr_t *xvap)
        if (XVA_ISSET_REQ(xvap, XAT_REPARSE))
                *attrs |= (xoap->xoa_reparse == 0) ? 0 :
                    XAT0_REPARSE;
+       if (XVA_ISSET_REQ(xvap, XAT_OFFLINE))
+               *attrs |= (xoap->xoa_offline == 0) ? 0 :
+                   XAT0_OFFLINE;
+       if (XVA_ISSET_REQ(xvap, XAT_SPARSE))
+               *attrs |= (xoap->xoa_sparse == 0) ? 0 :
+                   XAT0_SPARSE;
 }
 
 static void *
@@ -204,6 +215,7 @@ zfs_log_fuid_domains(zfs_fuid_info_t *fuidp, void *start)
        }
        return (start);
 }
+#endif /* HAVE_XVATTR */
 
 /*
  * zfs_log_create() is used to handle TX_CREATE, TX_CREATE_ATTR, TX_MKDIR,
@@ -231,13 +243,14 @@ zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
     zfs_fuid_info_t *fuidp, vattr_t *vap)
 {
        itx_t *itx;
-       uint64_t seq;
        lr_create_t *lr;
+#ifdef HAVE_XVATTR
        lr_acl_create_t *lracl;
+       xvattr_t *xvap = (xvattr_t *)vap;
+#endif /* HAVE_XVATTR */
        size_t aclsize;
        size_t xvatsize = 0;
        size_t txsize;
-       xvattr_t *xvap = (xvattr_t *)vap;
        void *end;
        size_t lrsize;
        size_t namesize = strlen(name) + 1;
@@ -255,8 +268,10 @@ zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
                fuidsz += fuidp->z_fuid_cnt * sizeof (uint64_t);
        }
 
+#ifdef HAVE_XVATTR
        if (vap->va_mask & AT_XVATTR)
                xvatsize = ZIL_XVAT_SIZE(xvap->xva_mapsize);
+#endif /* HAVE_XVATTR */
 
        if ((int)txtype == TX_CREATE_ATTR || (int)txtype == TX_MKDIR_ATTR ||
            (int)txtype == TX_CREATE || (int)txtype == TX_MKDIR ||
@@ -287,18 +302,19 @@ zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
        } else {
                lr->lr_gid = fuidp->z_fuid_group;
        }
-       (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen,
+       (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(ZTOZSB(zp)), &lr->lr_gen,
            sizeof (uint64_t));
-       (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs),
+       (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(ZTOZSB(zp)),
            lr->lr_crtime, sizeof (uint64_t) * 2);
 
-       if (sa_lookup(zp->z_sa_hdl, SA_ZPL_RDEV(zp->z_zfsvfs), &lr->lr_rdev,
+       if (sa_lookup(zp->z_sa_hdl, SA_ZPL_RDEV(ZTOZSB(zp)), &lr->lr_rdev,
            sizeof (lr->lr_rdev)) != 0)
                lr->lr_rdev = 0;
 
        /*
         * Fill in xvattr info if any
         */
+#ifdef HAVE_XVATTR
        if (vap->va_mask & AT_XVATTR) {
                zfs_log_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), xvap);
                end = (caddr_t)lr + lrsize + xvatsize;
@@ -328,14 +344,15 @@ zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
                end = zfs_log_fuid_ids(fuidp, end);
                end = zfs_log_fuid_domains(fuidp, end);
        }
+#else
+       end = (caddr_t)lr + lrsize;
+#endif /* HAVE_XVATTR */
        /*
         * Now place file name in log record
         */
        bcopy(name, end, namesize);
 
-       seq = zil_itx_assign(zilog, itx, tx);
-       dzp->z_last_itx = seq;
-       zp->z_last_itx = seq;
+       zil_itx_assign(zilog, itx, tx);
 }
 
 /*
@@ -343,10 +360,9 @@ 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)
+       znode_t *dzp, char *name, uint64_t foid)
 {
        itx_t *itx;
-       uint64_t seq;
        lr_remove_t *lr;
        size_t namesize = strlen(name) + 1;
 
@@ -358,8 +374,9 @@ zfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
        lr->lr_doid = dzp->z_id;
        bcopy(name, (char *)(lr + 1), namesize);
 
-       seq = zil_itx_assign(zilog, itx, tx);
-       dzp->z_last_itx = seq;
+       itx->itx_oid = foid;
+
+       zil_itx_assign(zilog, itx, tx);
 }
 
 /*
@@ -370,7 +387,6 @@ zfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
        znode_t *dzp, znode_t *zp, char *name)
 {
        itx_t *itx;
-       uint64_t seq;
        lr_link_t *lr;
        size_t namesize = strlen(name) + 1;
 
@@ -383,9 +399,7 @@ zfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
        lr->lr_link_obj = zp->z_id;
        bcopy(name, (char *)(lr + 1), namesize);
 
-       seq = zil_itx_assign(zilog, itx, tx);
-       dzp->z_last_itx = seq;
-       zp->z_last_itx = seq;
+       zil_itx_assign(zilog, itx, tx);
 }
 
 /*
@@ -396,7 +410,6 @@ zfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
     znode_t *dzp, znode_t *zp, char *name, char *link)
 {
        itx_t *itx;
-       uint64_t seq;
        lr_create_t *lr;
        size_t namesize = strlen(name) + 1;
        size_t linksize = strlen(link) + 1;
@@ -411,16 +424,14 @@ zfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
        lr->lr_uid = zp->z_uid;
        lr->lr_gid = zp->z_gid;
        lr->lr_mode = zp->z_mode;
-       (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen,
+       (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(ZTOZSB(zp)), &lr->lr_gen,
            sizeof (uint64_t));
-       (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs),
+       (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(ZTOZSB(zp)),
            lr->lr_crtime, sizeof (uint64_t) * 2);
        bcopy(name, (char *)(lr + 1), namesize);
        bcopy(link, (char *)(lr + 1) + namesize, linksize);
 
-       seq = zil_itx_assign(zilog, itx, tx);
-       dzp->z_last_itx = seq;
-       zp->z_last_itx = seq;
+       zil_itx_assign(zilog, itx, tx);
 }
 
 /*
@@ -431,7 +442,6 @@ 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)
 {
        itx_t *itx;
-       uint64_t seq;
        lr_rename_t *lr;
        size_t snamesize = strlen(sname) + 1;
        size_t dnamesize = strlen(dname) + 1;
@@ -445,11 +455,9 @@ zfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
        lr->lr_tdoid = tdzp->z_id;
        bcopy(sname, (char *)(lr + 1), snamesize);
        bcopy(dname, (char *)(lr + 1) + snamesize, dnamesize);
+       itx->itx_oid = szp->z_id;
 
-       seq = zil_itx_assign(zilog, itx, tx);
-       sdzp->z_last_itx = seq;
-       tdzp->z_last_itx = seq;
-       szp->z_last_itx = seq;
+       zil_itx_assign(zilog, itx, tx);
 }
 
 /*
@@ -501,7 +509,7 @@ zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
                itx = zil_itx_create(txtype, sizeof (*lr) +
                    (write_state == WR_COPIED ? len : 0));
                lr = (lr_write_t *)&itx->itx_lr;
-               if (write_state == WR_COPIED && dmu_read(zp->z_zfsvfs->z_os,
+               if (write_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));
@@ -518,15 +526,13 @@ zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
                lr->lr_blkoff = 0;
                BP_ZERO(&lr->lr_blkptr);
 
-               itx->itx_private = zp->z_zfsvfs;
+               itx->itx_private = ZTOZSB(zp);
 
-               if ((zp->z_sync_cnt != 0) || (fsync_cnt != 0) ||
-                   (ioflag & (FSYNC | FDSYNC)))
-                       itx->itx_sync = B_TRUE;
-               else
+               if (!(ioflag & (FSYNC | FDSYNC)) && (zp->z_sync_cnt == 0) &&
+                   (fsync_cnt == 0))
                        itx->itx_sync = B_FALSE;
 
-               zp->z_last_itx = zil_itx_assign(zilog, itx, tx);
+               zil_itx_assign(zilog, itx, tx);
 
                off += len;
                resid -= len;
@@ -541,7 +547,6 @@ zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
        znode_t *zp, uint64_t off, uint64_t len)
 {
        itx_t *itx;
-       uint64_t seq;
        lr_truncate_t *lr;
 
        if (zil_replaying(zilog, tx) || zp->z_unlinked)
@@ -554,21 +559,21 @@ zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
        lr->lr_length = len;
 
        itx->itx_sync = (zp->z_sync_cnt != 0);
-       seq = zil_itx_assign(zilog, itx, tx);
-       zp->z_last_itx = seq;
+       zil_itx_assign(zilog, itx, tx);
 }
 
 /*
  * zfs_log_setattr() handles TX_SETATTR transactions.
  */
 void
-zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
-       znode_t *zp, vattr_t *vap, uint_t mask_applied, zfs_fuid_info_t *fuidp)
+zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype, znode_t *zp,
+    struct iattr *attr, uint_t mask_applied, zfs_fuid_info_t *fuidp)
 {
        itx_t           *itx;
-       uint64_t        seq;
        lr_setattr_t    *lr;
+#ifdef HAVE_XVATTR
        xvattr_t        *xvap = (xvattr_t *)vap;
+#endif /* HAVEXVATTR */
        size_t          recsize = sizeof (lr_setattr_t);
        void            *start;
 
@@ -580,32 +585,35 @@ zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
         * for lr_attr_t + xvattr mask, mapsize and create time
         * plus actual attribute values
         */
-       if (vap->va_mask & AT_XVATTR)
+#ifdef HAVE_XVATTR
+       if (attr->ia_valid & AT_XVATTR)
                recsize = sizeof (*lr) + ZIL_XVAT_SIZE(xvap->xva_mapsize);
 
        if (fuidp)
                recsize += fuidp->z_domain_str_sz;
+#endif /* HAVE_XVATTR */
 
        itx = zil_itx_create(txtype, recsize);
        lr = (lr_setattr_t *)&itx->itx_lr;
        lr->lr_foid = zp->z_id;
        lr->lr_mask = (uint64_t)mask_applied;
-       lr->lr_mode = (uint64_t)vap->va_mode;
-       if ((mask_applied & AT_UID) && IS_EPHEMERAL(vap->va_uid))
+       lr->lr_mode = (uint64_t)attr->ia_mode;
+       if ((mask_applied & ATTR_UID) && IS_EPHEMERAL(attr->ia_uid))
                lr->lr_uid = fuidp->z_fuid_owner;
        else
-               lr->lr_uid = (uint64_t)vap->va_uid;
+               lr->lr_uid = (uint64_t)attr->ia_uid;
 
-       if ((mask_applied & AT_GID) && IS_EPHEMERAL(vap->va_gid))
+       if ((mask_applied & ATTR_GID) && IS_EPHEMERAL(attr->ia_gid))
                lr->lr_gid = fuidp->z_fuid_group;
        else
-               lr->lr_gid = (uint64_t)vap->va_gid;
+               lr->lr_gid = (uint64_t)attr->ia_gid;
 
-       lr->lr_size = (uint64_t)vap->va_size;
-       ZFS_TIME_ENCODE(&vap->va_atime, lr->lr_atime);
-       ZFS_TIME_ENCODE(&vap->va_mtime, lr->lr_mtime);
+       lr->lr_size = (uint64_t)attr->ia_size;
+       ZFS_TIME_ENCODE(&attr->ia_atime, lr->lr_atime);
+       ZFS_TIME_ENCODE(&attr->ia_mtime, lr->lr_mtime);
        start = (lr_setattr_t *)(lr + 1);
-       if (vap->va_mask & AT_XVATTR) {
+#ifdef HAVE_XVATTR
+       if (attr->ia_valid & ATTR_XVATTR) {
                zfs_log_xvattr((lr_attr_t *)start, xvap);
                start = (caddr_t)start + ZIL_XVAT_SIZE(xvap->xva_mapsize);
        }
@@ -616,10 +624,10 @@ zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
 
        if (fuidp)
                (void) zfs_log_fuid_domains(fuidp, start);
+#endif /* HAVE_XVATTR */
 
        itx->itx_sync = (zp->z_sync_cnt != 0);
-       seq = zil_itx_assign(zilog, itx, tx);
-       zp->z_last_itx = seq;
+       zil_itx_assign(zilog, itx, tx);
 }
 
 /*
@@ -630,7 +638,6 @@ zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp,
     vsecattr_t *vsecp, zfs_fuid_info_t *fuidp)
 {
        itx_t *itx;
-       uint64_t seq;
        lr_acl_v0_t *lrv0;
        lr_acl_t *lr;
        int txtype;
@@ -641,7 +648,7 @@ zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp,
        if (zil_replaying(zilog, tx) || zp->z_unlinked)
                return;
 
-       txtype = (zp->z_zfsvfs->z_version < ZPL_VERSION_FUID) ?
+       txtype = (ZTOZSB(zp)->z_version < ZPL_VERSION_FUID) ?
            TX_ACL_V0 : TX_ACL;
 
        if (txtype == TX_ACL)
@@ -679,13 +686,14 @@ zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp,
 
                start = (caddr_t)start + ZIL_ACE_LENGTH(aclbytes);
 
+#ifdef HAVE_XVATTR
                if (fuidp) {
                        start = zfs_log_fuid_ids(fuidp, start);
                        (void) zfs_log_fuid_domains(fuidp, start);
                }
+#endif /* HAVE_XVATTR */
        }
 
        itx->itx_sync = (zp->z_sync_cnt != 0);
-       seq = zil_itx_assign(zilog, itx, tx);
-       zp->z_last_itx = seq;
+       zil_itx_assign(zilog, itx, tx);
 }