Skip to content

Commit

Permalink
Use dsl_dataset_snap_lookup()
Browse files Browse the repository at this point in the history
Retire the dmu_snapshot_id() function which was introduced in the
initial .zfs control directory implementation.  There is already
an existing dsl_dataset_snap_lookup() which does exactly what we
need, and the dmu_snapshot_id() function as implemented is racy.

openzfs#1215 (comment)

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#1238
  • Loading branch information
behlendorf authored and unya committed Dec 13, 2013
1 parent d85adf7 commit ff2c595
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 35 deletions.
2 changes: 1 addition & 1 deletion include/sys/dmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ extern uint64_t dmu_objset_syncprop(objset_t *os);
extern uint64_t dmu_objset_logbias(objset_t *os);
extern int dmu_snapshot_list_next(objset_t *os, int namelen, char *name,
uint64_t *id, uint64_t *offp, boolean_t *case_conflict);
extern int dmu_snapshot_id(objset_t *os, const char *snapname, uint64_t *idp);
extern int dmu_snapshot_lookup(objset_t *os, const char *name, uint64_t *val);
extern int dmu_snapshot_realname(objset_t *os, char *name, char *real,
int maxlen, boolean_t *conflict);
extern int dmu_dir_list_next(objset_t *os, int namelen, char *name,
Expand Down
2 changes: 2 additions & 0 deletions include/sys/dsl_dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ int dsl_dataset_block_kill(dsl_dataset_t *ds, const blkptr_t *bp,
boolean_t dsl_dataset_block_freeable(dsl_dataset_t *ds, const blkptr_t *bp,
uint64_t blk_birth);
uint64_t dsl_dataset_prev_snap_txg(dsl_dataset_t *ds);
int dsl_dataset_snap_lookup(dsl_dataset_t *ds, const char *name,
uint64_t *value);

void dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx);
void dsl_dataset_stats(dsl_dataset_t *os, nvlist_t *nv);
Expand Down
33 changes: 2 additions & 31 deletions module/zfs/dmu_objset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1573,39 +1573,10 @@ dmu_snapshot_list_next(objset_t *os, int namelen, char *name,
return (0);
}

/*
* Determine the objset id for a given snapshot name.
*/
int
dmu_snapshot_id(objset_t *os, const char *snapname, uint64_t *idp)
dmu_snapshot_lookup(objset_t *os, const char *name, uint64_t *value)
{
dsl_dataset_t *ds = os->os_dsl_dataset;
zap_cursor_t cursor;
zap_attribute_t attr;
int error;

if (ds->ds_phys->ds_snapnames_zapobj == 0)
return (ENOENT);

zap_cursor_init(&cursor, ds->ds_dir->dd_pool->dp_meta_objset,
ds->ds_phys->ds_snapnames_zapobj);

error = zap_cursor_move_to_key(&cursor, snapname, MT_EXACT);
if (error) {
zap_cursor_fini(&cursor);
return (error);
}

error = zap_cursor_retrieve(&cursor, &attr);
if (error) {
zap_cursor_fini(&cursor);
return (error);
}

*idp = attr.za_first_integer;
zap_cursor_fini(&cursor);

return (0);
return dsl_dataset_snap_lookup(os->os_dsl_dataset, name, value);
}

int
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dsl_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ dsl_dataset_get_snapname(dsl_dataset_t *ds)
return (err);
}

static int
int
dsl_dataset_snap_lookup(dsl_dataset_t *ds, const char *name, uint64_t *value)
{
objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset;
Expand Down
4 changes: 2 additions & 2 deletions module/zfs/zfs_ctldir.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ zfsctl_snapdir_lookup(struct inode *dip, char *name, struct inode **ipp,

ZFS_ENTER(zsb);

error = dmu_snapshot_id(zsb->z_os, name, &id);
error = dmu_snapshot_lookup(zsb->z_os, name, &id);
if (error) {
ZFS_EXIT(zsb);
return (error);
Expand Down Expand Up @@ -909,7 +909,7 @@ zfsctl_lookup_objset(struct super_block *sb, uint64_t objsetid, zfs_sb_t **zsbp)
*/
sep = avl_first(&zsb->z_ctldir_snaps);
while (sep != NULL) {
error = dmu_snapshot_id(zsb->z_os, sep->se_name, &id);
error = dmu_snapshot_lookup(zsb->z_os, sep->se_name, &id);
if (error)
goto out;

Expand Down

0 comments on commit ff2c595

Please sign in to comment.