Skip to content

Commit 906a7d8

Browse files
committed
64-bit z_seq
Signed-off-by: Ameer Hamza <ahamza@ixsystems.com>
1 parent be849a2 commit 906a7d8

13 files changed

Lines changed: 117 additions & 113 deletions

File tree

include/os/linux/zfs/sys/trace_acl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ DECLARE_EVENT_CLASS(zfs_ace_class,
5454
__field(uint8_t, z_atime_dirty)
5555
__field(uint8_t, z_zn_prefetch)
5656
__field(uint_t, z_blksz)
57-
__field(uint_t, z_seq)
57+
__field(uint64_t, z_seq)
5858
__field(uint64_t, z_mapcnt)
5959
__field(uint64_t, z_size)
6060
__field(uint64_t, z_pflags)
@@ -111,7 +111,7 @@ DECLARE_EVENT_CLASS(zfs_ace_class,
111111
__entry->mask_matched = mask_matched;
112112
),
113113
TP_printk("zn { id %llu unlinked %u atime_dirty %u "
114-
"zn_prefetch %u blksz %u seq %u "
114+
"zn_prefetch %u blksz %u seq %llu "
115115
"mapcnt %llu size %llu pflags %llu "
116116
"sync_cnt %u "
117117
"mode 0x%x is_sa %d is_ctldir %d "

include/sys/zfs_znode.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,26 @@ extern "C" {
116116
#define SA_ZPL_SEQ(z) z->z_attr_table[ZPL_SEQ]
117117

118118
/*
119-
* Persist zp->z_seq into the SA bulk and mark the file as carrying
120-
* SA_ZPL_SEQ in its layout. No-op for legacy (non-SA-native) znodes
121-
* since SA_ZPL_SEQ cannot be added to their layout. Caller's bulk MUST
122-
* include SA_ZPL_FLAGS so the ZFS_HAS_SEQ bit reaches disk in the same
123-
* transaction.
119+
* may_grow for a dmu_tx_hold_sa() that may persist z_seq: the SA layout
120+
* grows the first time SA_ZPL_SEQ is added, so grow until ZFS_HAS_SEQ is
121+
* set. Mirrors ZFS_PROJID first-set growth.
124122
*/
125-
#define ZFS_PERSIST_SEQ(zp, bulk, count, seqp) \
123+
#define ZFS_SEQ_MAY_GROW(zp) \
124+
(((zp)->z_pflags & ZFS_HAS_SEQ) ? B_FALSE : B_TRUE)
125+
126+
/*
127+
* Persist zp->z_seq: set ZFS_HAS_SEQ and add SA_ZPL_SEQ to the caller's
128+
* bulk. No-op for legacy (non-SA-native) znodes. Caller's bulk MUST
129+
* include SA_ZPL_FLAGS so the bit reaches disk in the same transaction.
130+
* Chunked writers add SA_ZPL_SEQ once before their loop and set
131+
* ZFS_HAS_SEQ per chunk instead.
132+
*/
133+
#define ZFS_PERSIST_SEQ(zp, bulk, count) \
126134
{ \
127135
if ((zp)->z_is_sa) { \
128-
*(seqp) = (zp)->z_seq; \
129136
(zp)->z_pflags |= ZFS_HAS_SEQ; \
130137
SA_ADD_BULK_ATTR((bulk), (count), SA_ZPL_SEQ(ZTOZSB(zp)), \
131-
NULL, (seqp), sizeof (uint64_t)); \
138+
NULL, &(zp)->z_seq, sizeof ((zp)->z_seq)); \
132139
} \
133140
}
134141

@@ -214,7 +221,7 @@ typedef struct znode {
214221
boolean_t z_is_ctldir; /* are we .zfs entry */
215222
boolean_t z_suspended; /* extra ref from a suspend? */
216223
uint_t z_blksz; /* block size in bytes */
217-
uint_t z_seq; /* modification sequence number */
224+
uint64_t z_seq; /* modification sequence number */
218225
uint64_t z_mapcnt; /* number of pages mapped to file */
219226
uint64_t z_dnodesize; /* dnode size */
220227
uint64_t z_size; /* file size (cached) */

module/os/freebsd/zfs/zfs_acl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ zfs_aclset_common(znode_t *zp, zfs_acl_t *aclp, cred_t *cr, dmu_tx_t *tx)
11701170
dmu_object_type_t otype;
11711171
zfs_acl_locator_cb_t locate = { 0 };
11721172
uint64_t mode;
1173-
sa_bulk_attr_t bulk[5];
1173+
sa_bulk_attr_t bulk[6];
11741174
uint64_t ctime[2];
11751175
int count = 0;
11761176
zfs_acl_phys_t acl_phys;
@@ -1316,6 +1316,7 @@ zfs_aclset_common(znode_t *zp, zfs_acl_t *aclp, cred_t *cr, dmu_tx_t *tx)
13161316
zp->z_pflags |= ZFS_ACL_TRIVIAL;
13171317

13181318
zfs_tstamp_update_setup(zp, STATE_CHANGED, NULL, ctime);
1319+
ZFS_PERSIST_SEQ(zp, bulk, count);
13191320
return (sa_bulk_update(zp->z_sa_hdl, bulk, count, tx));
13201321
}
13211322

module/os/freebsd/zfs/zfs_dir.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ zfs_purgedir(znode_t *dzp)
394394
(ZTOV(xzp)->v_type == VLNK));
395395

396396
tx = dmu_tx_create(zfsvfs->z_os);
397-
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
397+
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, ZFS_SEQ_MAY_GROW(dzp));
398398
dmu_tx_hold_zap(tx, dzp->z_id, FALSE, zap->za_name);
399-
dmu_tx_hold_sa(tx, xzp->z_sa_hdl, B_FALSE);
399+
dmu_tx_hold_sa(tx, xzp->z_sa_hdl, ZFS_SEQ_MAY_GROW(xzp));
400400
dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
401401
/* Is this really needed ? */
402402
zfs_sa_upgrade_txholds(tx, xzp);
@@ -584,7 +584,7 @@ zfs_link_create(znode_t *dzp, const char *name, znode_t *zp, dmu_tx_t *tx,
584584
vnode_t *vp = ZTOV(zp);
585585
uint64_t value;
586586
int zp_is_dir = (vp->v_type == VDIR);
587-
sa_bulk_attr_t bulk[5];
587+
sa_bulk_attr_t bulk[6];
588588
uint64_t mtime[2], ctime[2];
589589
int count = 0;
590590
int error;
@@ -647,6 +647,7 @@ zfs_link_create(znode_t *dzp, const char *name, znode_t *zp, dmu_tx_t *tx,
647647
ctime, sizeof (ctime));
648648
zfs_tstamp_update_setup(zp, STATE_CHANGED, mtime,
649649
ctime);
650+
ZFS_PERSIST_SEQ(zp, bulk, count);
650651
}
651652
error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
652653
ASSERT0(error);
@@ -665,6 +666,7 @@ zfs_link_create(znode_t *dzp, const char *name, znode_t *zp, dmu_tx_t *tx,
665666
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
666667
&dzp->z_pflags, sizeof (dzp->z_pflags));
667668
zfs_tstamp_update_setup(dzp, CONTENT_MODIFIED, mtime, ctime);
669+
ZFS_PERSIST_SEQ(dzp, bulk, count);
668670
error = sa_bulk_update(dzp->z_sa_hdl, bulk, count, tx);
669671
ASSERT0(error);
670672
return (0);
@@ -729,7 +731,7 @@ zfs_link_destroy(znode_t *dzp, const char *name, znode_t *zp, dmu_tx_t *tx,
729731
vnode_t *vp = ZTOV(zp);
730732
int zp_is_dir = (vp->v_type == VDIR);
731733
boolean_t unlinked = B_FALSE;
732-
sa_bulk_attr_t bulk[5];
734+
sa_bulk_attr_t bulk[6];
733735
uint64_t mtime[2], ctime[2];
734736
int count = 0;
735737
int error;
@@ -771,6 +773,7 @@ zfs_link_destroy(znode_t *dzp, const char *name, znode_t *zp, dmu_tx_t *tx,
771773
NULL, &zp->z_pflags, sizeof (zp->z_pflags));
772774
zfs_tstamp_update_setup(zp, STATE_CHANGED, mtime,
773775
ctime);
776+
ZFS_PERSIST_SEQ(zp, bulk, count);
774777
}
775778
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs),
776779
NULL, &zp->z_links, sizeof (zp->z_links));
@@ -797,6 +800,7 @@ zfs_link_destroy(znode_t *dzp, const char *name, znode_t *zp, dmu_tx_t *tx,
797800
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs),
798801
NULL, &dzp->z_pflags, sizeof (dzp->z_pflags));
799802
zfs_tstamp_update_setup(dzp, CONTENT_MODIFIED, mtime, ctime);
803+
ZFS_PERSIST_SEQ(dzp, bulk, count);
800804
error = sa_bulk_update(dzp->z_sa_hdl, bulk, count, tx);
801805
ASSERT0(error);
802806

module/os/freebsd/zfs/zfs_vnops_os.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ zfs_create(znode_t *dzp, const char *name, vattr_t *vap, int excl, int mode,
11381138
if (fuid_dirtied)
11391139
zfs_fuid_txhold(zfsvfs, tx);
11401140
dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
1141-
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
1141+
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, ZFS_SEQ_MAY_GROW(dzp));
11421142
if (!zfsvfs->z_use_sa &&
11431143
acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
11441144
dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
@@ -1269,7 +1269,8 @@ zfs_remove_(vnode_t *dvp, vnode_t *vp, const char *name, cred_t *cr)
12691269
*/
12701270
tx = dmu_tx_create(zfsvfs->z_os);
12711271
dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1272-
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1272+
dmu_tx_hold_sa(tx, zp->z_sa_hdl, ZFS_SEQ_MAY_GROW(zp));
1273+
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, ZFS_SEQ_MAY_GROW(dzp));
12731274
zfs_sa_upgrade_txholds(tx, zp);
12741275
zfs_sa_upgrade_txholds(tx, dzp);
12751276

@@ -1497,6 +1498,7 @@ zfs_mkdir(znode_t *dzp, const char *dirname, vattr_t *vap, znode_t **zpp,
14971498
tx = dmu_tx_create(zfsvfs->z_os);
14981499
dmu_tx_hold_zap(tx, dzp->z_id, TRUE, dirname);
14991500
dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
1501+
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, ZFS_SEQ_MAY_GROW(dzp));
15001502
fuid_dirtied = zfsvfs->z_fuid_dirty;
15011503
if (fuid_dirtied)
15021504
zfs_fuid_txhold(zfsvfs, tx);
@@ -1605,7 +1607,8 @@ zfs_rmdir_(vnode_t *dvp, vnode_t *vp, const char *name, cred_t *cr)
16051607

16061608
tx = dmu_tx_create(zfsvfs->z_os);
16071609
dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1608-
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1610+
dmu_tx_hold_sa(tx, zp->z_sa_hdl, ZFS_SEQ_MAY_GROW(zp));
1611+
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, ZFS_SEQ_MAY_GROW(dzp));
16091612
dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
16101613
zfs_sa_upgrade_txholds(tx, zp);
16111614
zfs_sa_upgrade_txholds(tx, dzp);
@@ -2318,7 +2321,7 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr, zidmap_t *mnt_ns)
23182321
boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
23192322
boolean_t fuid_dirtied = B_FALSE;
23202323
boolean_t handle_eadir = B_FALSE;
2321-
sa_bulk_attr_t bulk[7], xattr_bulk[7];
2324+
sa_bulk_attr_t bulk[8], xattr_bulk[7];
23222325
int count = 0, xattr_count = 0;
23232326

23242327
if (mask == 0)
@@ -2758,7 +2761,8 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr, zidmap_t *mnt_ns)
27582761
if (((mask & AT_XVATTR) &&
27592762
XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) ||
27602763
(projid != ZFS_INVALID_PROJID &&
2761-
!(zp->z_pflags & ZFS_PROJID)))
2764+
!(zp->z_pflags & ZFS_PROJID)) ||
2765+
!(zp->z_pflags & ZFS_HAS_SEQ))
27622766
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
27632767
else
27642768
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
@@ -2921,6 +2925,8 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr, zidmap_t *mnt_ns)
29212925
}
29222926
}
29232927

2928+
ZFS_PERSIST_SEQ(zp, bulk, count);
2929+
29242930
/*
29252931
* Do this after setting timestamps to prevent timestamp
29262932
* update from toggling bit
@@ -3464,16 +3470,16 @@ zfs_do_rename_impl(vnode_t *sdvp, vnode_t **svpp, struct componentname *scnp,
34643470
}
34653471

34663472
tx = dmu_tx_create(zfsvfs->z_os);
3467-
dmu_tx_hold_sa(tx, szp->z_sa_hdl, B_FALSE);
3468-
dmu_tx_hold_sa(tx, sdzp->z_sa_hdl, B_FALSE);
3473+
dmu_tx_hold_sa(tx, szp->z_sa_hdl, ZFS_SEQ_MAY_GROW(szp));
3474+
dmu_tx_hold_sa(tx, sdzp->z_sa_hdl, ZFS_SEQ_MAY_GROW(sdzp));
34693475
dmu_tx_hold_zap(tx, sdzp->z_id, FALSE, snm);
34703476
dmu_tx_hold_zap(tx, tdzp->z_id, TRUE, tnm);
34713477
if (sdzp != tdzp) {
3472-
dmu_tx_hold_sa(tx, tdzp->z_sa_hdl, B_FALSE);
3478+
dmu_tx_hold_sa(tx, tdzp->z_sa_hdl, ZFS_SEQ_MAY_GROW(tdzp));
34733479
zfs_sa_upgrade_txholds(tx, tdzp);
34743480
}
34753481
if (tzp) {
3476-
dmu_tx_hold_sa(tx, tzp->z_sa_hdl, B_FALSE);
3482+
dmu_tx_hold_sa(tx, tzp->z_sa_hdl, ZFS_SEQ_MAY_GROW(tzp));
34773483
zfs_sa_upgrade_txholds(tx, tzp);
34783484
}
34793485

@@ -3672,7 +3678,7 @@ zfs_symlink(znode_t *dzp, const char *name, vattr_t *vap,
36723678
dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
36733679
dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
36743680
ZFS_SA_BASE_ATTR_SIZE + len);
3675-
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
3681+
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, ZFS_SEQ_MAY_GROW(dzp));
36763682
if (!zfsvfs->z_use_sa && acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
36773683
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
36783684
acl_ids.z_aclp->z_acl_bytes);
@@ -3894,7 +3900,8 @@ zfs_link(znode_t *tdzp, znode_t *szp, const char *name, cred_t *cr,
38943900
}
38953901

38963902
tx = dmu_tx_create(zfsvfs->z_os);
3897-
dmu_tx_hold_sa(tx, szp->z_sa_hdl, B_FALSE);
3903+
dmu_tx_hold_sa(tx, szp->z_sa_hdl, ZFS_SEQ_MAY_GROW(szp));
3904+
dmu_tx_hold_sa(tx, tdzp->z_sa_hdl, ZFS_SEQ_MAY_GROW(tdzp));
38983905
dmu_tx_hold_zap(tx, tdzp->z_id, TRUE, name);
38993906
zfs_sa_upgrade_txholds(tx, szp);
39003907
zfs_sa_upgrade_txholds(tx, tdzp);
@@ -4458,7 +4465,7 @@ zfs_putpages(struct vnode *vp, vm_page_t *ma, size_t len, int flags,
44584465
tx = dmu_tx_create(zfsvfs->z_os);
44594466
dmu_tx_hold_write(tx, zp->z_id, off, len);
44604467

4461-
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
4468+
dmu_tx_hold_sa(tx, zp->z_sa_hdl, ZFS_SEQ_MAY_GROW(zp));
44624469
zfs_sa_upgrade_txholds(tx, zp);
44634470
err = dmu_tx_assign(tx, DMU_TX_WAIT);
44644471
if (err != 0) {
@@ -4482,7 +4489,7 @@ zfs_putpages(struct vnode *vp, vm_page_t *ma, size_t len, int flags,
44824489

44834490
if (err == 0) {
44844491
uint64_t mtime[2], ctime[2];
4485-
sa_bulk_attr_t bulk[3];
4492+
sa_bulk_attr_t bulk[4];
44864493
int count = 0;
44874494

44884495
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
@@ -4492,6 +4499,7 @@ zfs_putpages(struct vnode *vp, vm_page_t *ma, size_t len, int flags,
44924499
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
44934500
&zp->z_pflags, 8);
44944501
zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime);
4502+
ZFS_PERSIST_SEQ(zp, bulk, count);
44954503
err = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
44964504
ASSERT0(err);
44974505

module/os/freebsd/zfs/zfs_znode_os.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,10 @@ zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz,
481481
if (sa_bulk_lookup(zp->z_sa_hdl, bulk, count) != 0 || zp->z_gen == 0 ||
482482
(dmu_objset_projectquota_enabled(zfsvfs->z_os) &&
483483
(zp->z_pflags & ZFS_PROJID) &&
484-
sa_lookup(zp->z_sa_hdl, SA_ZPL_PROJID(zfsvfs), &projid, 8) != 0)) {
484+
sa_lookup(zp->z_sa_hdl, SA_ZPL_PROJID(zfsvfs), &projid, 8) != 0) ||
485+
(zp->z_is_sa && (zp->z_pflags & ZFS_HAS_SEQ) &&
486+
sa_lookup(zp->z_sa_hdl, SA_ZPL_SEQ(zfsvfs),
487+
&zp->z_seq, sizeof (zp->z_seq)) != 0)) {
485488
if (hdl == NULL)
486489
sa_handle_destroy(zp->z_sa_hdl);
487490
zfs_vnode_forget(vp);
@@ -1668,7 +1671,7 @@ zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
16681671
zilog_t *zilog = zfsvfs->z_log;
16691672
uint64_t mode;
16701673
uint64_t mtime[2], ctime[2];
1671-
sa_bulk_attr_t bulk[3];
1674+
sa_bulk_attr_t bulk[4];
16721675
int count = 0;
16731676
int error;
16741677

@@ -1695,7 +1698,7 @@ zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
16951698
return (error);
16961699
log:
16971700
tx = dmu_tx_create(zfsvfs->z_os);
1698-
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1701+
dmu_tx_hold_sa(tx, zp->z_sa_hdl, ZFS_SEQ_MAY_GROW(zp));
16991702
zfs_sa_upgrade_txholds(tx, zp);
17001703
error = dmu_tx_assign(tx, DMU_TX_WAIT);
17011704
if (error) {
@@ -1708,6 +1711,7 @@ zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
17081711
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs),
17091712
NULL, &zp->z_pflags, 8);
17101713
zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime);
1714+
ZFS_PERSIST_SEQ(zp, bulk, count);
17111715
error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
17121716
ASSERT0(error);
17131717

module/os/linux/zfs/zfs_acl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ zfs_aclset_common(znode_t *zp, zfs_acl_t *aclp, cred_t *cr, dmu_tx_t *tx)
13601360
zfs_acl_locator_cb_t locate = { 0 };
13611361
uint64_t mode;
13621362
sa_bulk_attr_t bulk[6];
1363-
uint64_t ctime[2], change_seq;
1363+
uint64_t ctime[2];
13641364
int count = 0;
13651365
zfs_acl_phys_t acl_phys;
13661366

@@ -1501,7 +1501,7 @@ zfs_aclset_common(znode_t *zp, zfs_acl_t *aclp, cred_t *cr, dmu_tx_t *tx)
15011501
zp->z_pflags |= ZFS_ACL_TRIVIAL;
15021502

15031503
zfs_tstamp_update_setup(zp, STATE_CHANGED, NULL, ctime);
1504-
ZFS_PERSIST_SEQ(zp, bulk, count, &change_seq);
1504+
ZFS_PERSIST_SEQ(zp, bulk, count);
15051505
return (sa_bulk_update(zp->z_sa_hdl, bulk, count, tx));
15061506
}
15071507

0 commit comments

Comments
 (0)