Skip to content

Commit

Permalink
macOS changes for feature longnames
Browse files Browse the repository at this point in the history
Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Jan 16, 2025
1 parent f3b2202 commit 192b86e
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 179 deletions.
35 changes: 31 additions & 4 deletions include/os/macos/zfs/sys/zfs_vfsops_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ struct znode;
#endif
#endif

#define zfs_teardown_lock_t rrmlock_t
#define zfs_teardown_inactive_lock_t krwlock_t

/*
* Status of the zfs_unlinked_drain thread.
*/
Expand Down Expand Up @@ -81,28 +84,28 @@ struct zfsvfs {
boolean_t z_fuid_loaded; /* fuid tables are loaded */
boolean_t z_fuid_dirty; /* need to sync fuid table ? */
struct zfs_fuid_info *z_fuid_replay; /* fuid info for replay */
uint64_t z_assign; /* TXG_NOWAIT or set by zil_replay() */
zilog_t *z_log; /* intent log pointer */
uint_t z_acl_type; /* type of acl usable on this fs */
uint_t z_acl_mode; /* acl chmod/mode behavior */
uint_t z_acl_inherit; /* acl inheritance behavior */
zfs_case_t z_case; /* case-sense */
boolean_t z_utf8; /* utf8-only */
int z_norm; /* normalization flags */
boolean_t z_atime; /* enable atimes mount option */
boolean_t z_unmounted; /* unmounted */
rrmlock_t z_teardown_lock;
krwlock_t z_teardown_inactive_lock;
zfs_teardown_lock_t z_teardown_lock;
zfs_teardown_inactive_lock_t z_teardown_inactive_lock;
list_t z_all_znodes; /* all vnodes in the fs */
kmutex_t z_znodes_lock; /* lock for z_all_znodes */
struct vnode *z_ctldir; /* .zfs directory pointer */
uint64_t z_ctldir_startid; /* Start of snapdir range */
boolean_t z_show_ctldir; /* expose .zfs in the root dir */
boolean_t z_issnap; /* true if this is a snapshot */
boolean_t z_vscan; /* virus scan on/off */
boolean_t z_use_fuids; /* version allows fuids */
boolean_t z_replay; /* set during ZIL replay */
boolean_t z_use_sa; /* version allow system attributes */
boolean_t z_xattr_sa; /* allow xattrs to be stores as SA */
boolean_t z_longname; /* Dataset supports long names */
uint64_t z_version;
uint64_t z_shares_dir; /* hidden shares dir */
dataset_kstats_t z_kstat; /* fs kstats */
Expand Down Expand Up @@ -197,6 +200,30 @@ int zfs_vfs_uuid_gen(const char *osname, uuid_t uuid);
#define ZFS_TEARDOWN_HELD(zfsvfs) \
RRM_LOCK_HELD(&(zfsvfs)->z_teardown_lock)

#define ZFS_TEARDOWN_INACTIVE_INIT(zfsvfs) \
rw_init(&zfsvfs->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL);

#define ZFS_TEARDOWN_INACTIVE_DESTROY(zfsvfs) \
rw_destroy(&zfsvfs->z_teardown_inactive_lock);

#define ZFS_TEARDOWN_INACTIVE_TRY_ENTER_READ(zfsvfs) \
rw_tryenter(&zfsvfs->z_teardown_inactive_lock, RW_READER);

#define ZFS_TEARDOWN_INACTIVE_ENTER_READ(zfsvfs) \
rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER);

#define ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs) \
rw_exit(&zfsvfs->z_teardown_inactive_lock);

#define ZFS_TEARDOWN_INACTIVE_ENTER_WRITE(zfsvfs) \
rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_WRITER);

#define ZFS_TEARDOWN_INACTIVE_EXIT_WRITE(zfsvfs) \
rw_exit(&zfsvfs->z_teardown_inactive_lock);

#define ZFS_TEARDOWN_INACTIVE_WRITE_HELD(zfsvfs) \
rw_write_held(&(zfsvfs)->z_teardown_inactive_lock)

#define ZSB_XATTR 0x0001 /* Enable user xattrs */

/*
Expand Down
20 changes: 12 additions & 8 deletions module/os/macos/zfs/zfs_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,17 @@ zfs_unlinked_drain_task(void *arg)
{
zfsvfs_t *zfsvfs = arg;
zap_cursor_t zc;
zap_attribute_t zap;
zap_attribute_t *zap;
dmu_object_info_t doi;
znode_t *zp;
int error;

/*
* Iterate over the contents of the unlinked set.
*/
zap = zap_attribute_alloc();
for (zap_cursor_init(&zc, zfsvfs->z_os, zfsvfs->z_unlinkedobj);
zap_cursor_retrieve(&zc, &zap) == 0 &&
zap_cursor_retrieve(&zc, zap) == 0 &&
zfsvfs->z_drain_state == ZFS_DRAIN_RUNNING;
zap_cursor_advance(&zc)) {

Expand All @@ -498,7 +499,7 @@ zfs_unlinked_drain_task(void *arg)
*/

error = dmu_object_info(zfsvfs->z_os,
zap.za_first_integer, &doi);
zap->za_first_integer, &doi);
if (error != 0)
continue;

Expand All @@ -508,7 +509,7 @@ zfs_unlinked_drain_task(void *arg)
* We need to re-mark these list entries for deletion,
* so we pull them back into core and set zp->z_unlinked.
*/
error = zfs_zget(zfsvfs, zap.za_first_integer, &zp);
error = zfs_zget(zfsvfs, zap->za_first_integer, &zp);

/*
* We may pick up znodes that are already marked for deletion.
Expand All @@ -532,6 +533,7 @@ zfs_unlinked_drain_task(void *arg)
ASSERT3B(zfsvfs->z_unmounted, ==, B_FALSE);
}
zap_cursor_fini(&zc);
zap_attribute_free(zap);

mutex_enter(&zfsvfs->z_drain_lock);
zfsvfs->z_drain_state = ZFS_DRAIN_SHUTDOWN;
Expand Down Expand Up @@ -593,19 +595,20 @@ static int
zfs_purgedir(znode_t *dzp)
{
zap_cursor_t zc;
zap_attribute_t zap;
zap_attribute_t *zap;
znode_t *xzp;
dmu_tx_t *tx;
zfsvfs_t *zfsvfs = ZTOZSB(dzp);
zfs_dirlock_t dl;
int skipped = 0;
int error;

zap = zap_attribute_alloc();
for (zap_cursor_init(&zc, zfsvfs->z_os, dzp->z_id);
(error = zap_cursor_retrieve(&zc, &zap)) == 0;
zap_cursor_advance(&zc)) {
error = zfs_zget_ext(zfsvfs,
ZFS_DIRENT_OBJ(zap.za_first_integer), &xzp,
ZFS_DIRENT_OBJ(zap->za_first_integer), &xzp,
ZGET_FLAG_ASYNC);
if (error) {
skipped += 1;
Expand All @@ -614,7 +617,7 @@ zfs_purgedir(znode_t *dzp)

tx = dmu_tx_create(zfsvfs->z_os);
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
dmu_tx_hold_zap(tx, dzp->z_id, FALSE, zap.za_name);
dmu_tx_hold_zap(tx, dzp->z_id, FALSE, zap->za_name);
dmu_tx_hold_sa(tx, xzp->z_sa_hdl, B_FALSE);
dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
/* Is this really needed ? */
Expand All @@ -630,7 +633,7 @@ zfs_purgedir(znode_t *dzp)
}
memset(&dl, 0, sizeof (dl));
dl.dl_dzp = dzp;
dl.dl_name = zap.za_name;
dl.dl_name = zap->za_name;

error = zfs_link_destroy(&dl, xzp, tx, 0, NULL);
if (error)
Expand All @@ -641,6 +644,7 @@ zfs_purgedir(znode_t *dzp)
zfs_znode_asyncput(xzp);
}
zap_cursor_fini(&zc);
zap_attribute_free(zap);
if (error != ENOENT)
skipped += 1;
return (skipped);
Expand Down
Loading

0 comments on commit 192b86e

Please sign in to comment.