Ricardo Correia wrote:> On Wednesday 09 May 2007 04:57:53 Ricardo Correia wrote:
>> 2) In the end of zfs_zget(), if the requested object number is not
found,
>> it allocates a new znode with that object number. This
shouldn''t happen in
>> any FUSE operation.
>
> Apparently, I didn''t (and I still don''t) fully understand
this part of the
> code, but I still need it after all.
>
This code is not allocating new objects, rather it is re-creating vnodes
when they are no longer in memory (e.g., it was cleaned up after the
last reference was dropped, or this is the first time this object is
being referenced).
> So I propose only a very simple change - an added boolean parameter that
> allows zfs_zget() to return unlinked objects.
>
Could you file an RFE for this via the opensolaris bug-reporting
interface?
> See the attached patch (and sorry for the mismatched paths WRT the
OpenSolaris
> tree).
>
> Regards,
> Ricardo Correia
>
>
> ------------------------------------------------------------------------
>
> diff -r 1d5a1b751011 -r 26733593a5d0
src/lib/libzfscommon/include/sys/zfs_znode.h
> --- a/src/lib/libzfscommon/include/sys/zfs_znode.h Tue May 08 19:10:14 2007
+0100
> +++ b/src/lib/libzfscommon/include/sys/zfs_znode.h Wed May 09 21:43:30 2007
+0100
> @@ -255,7 +255,7 @@ extern int zfs_freesp(znode_t *, uint64_
> extern int zfs_freesp(znode_t *, uint64_t, uint64_t, int, boolean_t);
> extern void zfs_znode_init(void);
> extern void zfs_znode_fini(void);
> -extern int zfs_zget(zfsvfs_t *, uint64_t, znode_t **);
> +extern int zfs_zget(zfsvfs_t *, uint64_t, znode_t **, boolean_t);
> extern void zfs_zinactive(znode_t *);
> extern void zfs_znode_delete(znode_t *, dmu_tx_t *);
> extern void zfs_znode_free(znode_t *);
> diff -r 1d5a1b751011 -r 26733593a5d0 src/lib/libzpool/zfs_znode.c
> --- a/src/lib/libzpool/zfs_znode.c Tue May 08 19:10:14 2007 +0100
> +++ b/src/lib/libzpool/zfs_znode.c Wed May 09 21:43:30 2007 +0100
> @@ -315,7 +315,7 @@ zfs_init_fs(zfsvfs_t *zfsvfs, znode_t **
> for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
> mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
>
> - error = zfs_zget(zfsvfs, zfsvfs->z_root, zpp);
> + error = zfs_zget(zfsvfs, zfsvfs->z_root, zpp, B_FALSE);
> if (error)
> return (error);
> ASSERT3U((*zpp)->z_id, ==, zfsvfs->z_root);
> @@ -639,7 +639,7 @@ zfs_mknode(znode_t *dzp, vattr_t *vap, u
> }
>
> int
> -zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
> +zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp, boolean_t
zget_unlinked)
> {
> dmu_object_info_t doi;
> dmu_buf_t *db;
> @@ -674,7 +674,7 @@ zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_
> mutex_enter(&zp->z_lock);
>
> ASSERT3U(zp->z_id, ==, obj_num);
> - if (zp->z_unlinked) {
> + if (zp->z_unlinked && !zget_unlinked) {
> dmu_buf_rele(db, NULL);
> mutex_exit(&zp->z_lock);
> ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
> diff -r 1d5a1b751011 -r 26733593a5d0 src/zfs-fuse/zfs_acl.c
> --- a/src/zfs-fuse/zfs_acl.c Tue May 08 19:10:14 2007 +0100
> +++ b/src/zfs-fuse/zfs_acl.c Wed May 09 21:43:30 2007 +0100
> @@ -1366,7 +1366,7 @@ zfs_zaccess(znode_t *zp, int mode, cred_
> */
> if (is_attr) {
> if ((error = zfs_zget(zp->z_zfsvfs,
> - zp->z_phys->zp_parent, &xzp)) != 0) {
> + zp->z_phys->zp_parent, &xzp, B_FALSE)) != 0) {
> return (error);
> }
> check_zp = xzp;
> diff -r 1d5a1b751011 -r 26733593a5d0 src/zfs-fuse/zfs_dir.c
> --- a/src/zfs-fuse/zfs_dir.c Tue May 08 19:10:14 2007 +0100
> +++ b/src/zfs-fuse/zfs_dir.c Wed May 09 21:43:30 2007 +0100
> @@ -187,7 +187,7 @@ zfs_dirent_lock(zfs_dirlock_t **dlpp, zn
> zfs_dirent_unlock(dl);
> return (EEXIST);
> }
> - error = zfs_zget(zfsvfs, zoid, zpp);
> + error = zfs_zget(zfsvfs, zoid, zpp, B_FALSE);
> if (error) {
> zfs_dirent_unlock(dl);
> return (error);
> @@ -261,7 +261,7 @@ zfs_dirlook(znode_t *dzp, char *name, vn
> return (error);
> }
> rw_enter(&dzp->z_parent_lock, RW_READER);
> - error = zfs_zget(zfsvfs, dzp->z_phys->zp_parent, &zp);
> + error = zfs_zget(zfsvfs, dzp->z_phys->zp_parent, &zp,
B_FALSE);
> if (error == 0)
> *vpp = ZTOV(zp);
> rw_exit(&dzp->z_parent_lock);
> @@ -358,7 +358,7 @@ zfs_unlinked_drain(zfsvfs_t *zfsvfs)
> * 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, B_FALSE);
>
> /*
> * We may pick up znodes that are already marked for deletion.
> @@ -400,7 +400,7 @@ zfs_purgedir(znode_t *dzp)
> (error = zap_cursor_retrieve(&zc, &zap)) == 0;
> zap_cursor_advance(&zc)) {
> error = zfs_zget(zfsvfs,
> - ZFS_DIRENT_OBJ(zap.za_first_integer), &xzp);
> + ZFS_DIRENT_OBJ(zap.za_first_integer), &xzp, B_FALSE);
> ASSERT3U(error, ==, 0);
>
> ASSERT((ZTOV(xzp)->v_type == VREG) ||
> @@ -465,7 +465,7 @@ zfs_rmnode(znode_t *zp)
> * the xattr dir.
> */
> if (zp->z_phys->zp_xattr) {
> - error = zfs_zget(zfsvfs, zp->z_phys->zp_xattr, &xzp);
> + error = zfs_zget(zfsvfs, zp->z_phys->zp_xattr, &xzp, B_FALSE);
> ASSERT(error == 0);
> }
>
> diff -r 1d5a1b751011 -r 26733593a5d0 src/zfs-fuse/zfs_replay.c
> --- a/src/zfs-fuse/zfs_replay.c Tue May 08 19:10:14 2007 +0100
> +++ b/src/zfs-fuse/zfs_replay.c Wed May 09 21:43:30 2007 +0100
> @@ -88,7 +88,7 @@ zfs_replay_create(zfsvfs_t *zfsvfs, lr_c
> if (byteswap)
> byteswap_uint64_array(lr, sizeof (*lr));
>
> - if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
> + if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp, B_FALSE)) != 0)
> return (error);
>
> zfs_init_vattr(&va, AT_TYPE | AT_MODE | AT_UID | AT_GID,
> @@ -140,7 +140,7 @@ zfs_replay_remove(zfsvfs_t *zfsvfs, lr_r
> if (byteswap)
> byteswap_uint64_array(lr, sizeof (*lr));
>
> - if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
> + if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp, B_FALSE)) != 0)
> return (error);
>
> switch ((int)lr->lr_common.lrc_txtype) {
> @@ -169,10 +169,10 @@ zfs_replay_link(zfsvfs_t *zfsvfs, lr_lin
> if (byteswap)
> byteswap_uint64_array(lr, sizeof (*lr));
>
> - if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
> - return (error);
> -
> - if ((error = zfs_zget(zfsvfs, lr->lr_link_obj, &zp)) != 0) {
> + if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp, B_FALSE)) != 0)
> + return (error);
> +
> + if ((error = zfs_zget(zfsvfs, lr->lr_link_obj, &zp, B_FALSE)) !=
0) {
> VN_RELE(ZTOV(dzp));
> return (error);
> }
> @@ -196,10 +196,10 @@ zfs_replay_rename(zfsvfs_t *zfsvfs, lr_r
> if (byteswap)
> byteswap_uint64_array(lr, sizeof (*lr));
>
> - if ((error = zfs_zget(zfsvfs, lr->lr_sdoid, &sdzp)) != 0)
> - return (error);
> -
> - if ((error = zfs_zget(zfsvfs, lr->lr_tdoid, &tdzp)) != 0) {
> + if ((error = zfs_zget(zfsvfs, lr->lr_sdoid, &sdzp, B_FALSE)) != 0)
> + return (error);
> +
> + if ((error = zfs_zget(zfsvfs, lr->lr_tdoid, &tdzp, B_FALSE)) != 0)
{
> VN_RELE(ZTOV(sdzp));
> return (error);
> }
> @@ -223,7 +223,7 @@ zfs_replay_write(zfsvfs_t *zfsvfs, lr_wr
> if (byteswap)
> byteswap_uint64_array(lr, sizeof (*lr));
>
> - if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
> + if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp, B_FALSE)) != 0) {
> /*
> * As we can log writes out of order, it''s possible the
> * file has been removed. In this case just drop the write
> @@ -252,7 +252,7 @@ zfs_replay_truncate(zfsvfs_t *zfsvfs, lr
> if (byteswap)
> byteswap_uint64_array(lr, sizeof (*lr));
>
> - if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
> + if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp, B_FALSE)) != 0) {
> /*
> * As we can log truncates out of order, it''s possible the
> * file has been removed. In this case just drop the truncate
> @@ -287,7 +287,7 @@ zfs_replay_setattr(zfsvfs_t *zfsvfs, lr_
> if (byteswap)
> byteswap_uint64_array(lr, sizeof (*lr));
>
> - if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
> + if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp, B_FALSE)) != 0) {
> /*
> * As we can log setattrs out of order, it''s possible the
> * file has been removed. In this case just drop the setattr
> @@ -325,7 +325,7 @@ zfs_replay_acl(zfsvfs_t *zfsvfs, lr_acl_
> zfs_ace_byteswap(ace, lr->lr_aclcnt);
> }
>
> - if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
> + if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp, B_FALSE)) != 0) {
> /*
> * As we can log acls out of order, it''s possible the
> * file has been removed. In this case just drop the acl
> diff -r 1d5a1b751011 -r 26733593a5d0 src/zfs-fuse/zfs_vfsops.c
> --- a/src/zfs-fuse/zfs_vfsops.c Tue May 08 19:10:14 2007 +0100
> +++ b/src/zfs-fuse/zfs_vfsops.c Wed May 09 21:43:30 2007 +0100
> @@ -1005,7 +1005,7 @@ zfs_root(vfs_t *vfsp, vnode_t **vpp)
>
> ZFS_ENTER(zfsvfs);
>
> - error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp);
> + error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp, B_FALSE);
> if (error == 0)
> *vpp = ZTOV(rootzp);
>
> diff -r 1d5a1b751011 -r 26733593a5d0 src/zfs-fuse/zfs_vnops.c
> --- a/src/zfs-fuse/zfs_vnops.c Tue May 08 19:10:14 2007 +0100
> +++ b/src/zfs-fuse/zfs_vnops.c Wed May 09 21:43:30 2007 +0100
> @@ -834,7 +834,7 @@ zfs_get_data(void *arg, lr_write_t *lr,
> /*
> * Nothing to do if the file has been removed
> */
> - if (zfs_zget(zfsvfs, lr->lr_foid, &zp) != 0)
> + if (zfs_zget(zfsvfs, lr->lr_foid, &zp, B_FALSE) != 0)
> return (ENOENT);
> if (zp->z_unlinked) {
> VN_RELE(ZTOV(zp));
> @@ -1345,7 +1345,7 @@ top:
>
> if (delete_now) {
> if (zp->z_phys->zp_xattr) {
> - error = zfs_zget(zfsvfs, zp->z_phys->zp_xattr, &xzp);
> + error = zfs_zget(zfsvfs, zp->z_phys->zp_xattr, &xzp,
B_FALSE);
> ASSERT3U(error, ==, 0);
> ASSERT3U(xzp->z_phys->zp_links, ==, 2);
> dmu_buf_will_dirty(xzp->z_dbuf, tx);
> @@ -2109,7 +2109,7 @@ top:
> }
>
> if ((mask & (AT_UID | AT_GID)) && zp->z_phys->zp_xattr
!= 0) {
> - err = zfs_zget(zp->z_zfsvfs, zp->z_phys->zp_xattr,
&attrzp);
> + err = zfs_zget(zp->z_zfsvfs, zp->z_phys->zp_xattr, &attrzp,
B_FALSE);
> if (err) {
> dmu_tx_abort(tx);
> ZFS_EXIT(zfsvfs);
> @@ -2275,7 +2275,7 @@ zfs_rename_lock(znode_t *szp, znode_t *t
> return (0);
>
> if (rw == RW_READER) { /* i.e. not the first pass */
> - int error = zfs_zget(zp->z_zfsvfs, *oidp, &zp);
> + int error = zfs_zget(zp->z_zfsvfs, *oidp, &zp, B_FALSE);
> if (error)
> return (error);
> zl->zl_znode = zp;
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> zfs-code mailing list
> zfs-code at opensolaris.org
> http://opensolaris.org/mailman/listinfo/zfs-code