public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Zhi Yong Wu <zwu.kernel@gmail.com>
Cc: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>, xfs@oss.sgi.com
Subject: Re: [RFC PATCH 4/4] xfs: allow linkat() on O_TMPFILE files
Date: Tue, 26 Nov 2013 08:46:11 +1100	[thread overview]
Message-ID: <20131125214611.GI8803@dastard> (raw)
In-Reply-To: <1385379154-3802-5-git-send-email-zwu.kernel@gmail.com>

On Mon, Nov 25, 2013 at 07:32:34PM +0800, Zhi Yong Wu wrote:
> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
> 
> Enable O_TMPFILE support in linkat().
> 
> http://oss.sgi.com/archives/xfs/2013-08/msg00341.html
> 
> Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
> ---
>  fs/xfs/xfs_inode.c      |   23 +++++++++++++++++++++--
>  fs/xfs/xfs_trans_resv.c |   13 +++++++++++++
>  fs/xfs/xfs_trans_resv.h |    2 ++
>  3 files changed, 36 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
> index e1832de..7ab029b 100644
> --- a/fs/xfs/xfs_inode.c
> +++ b/fs/xfs/xfs_inode.c
> @@ -62,6 +62,8 @@ kmem_zone_t *xfs_inode_zone;
>  
>  STATIC int xfs_iflush_int(xfs_inode_t *, xfs_buf_t *);
>  
> +STATIC int xfs_iunlink_remove(xfs_trans_t *, xfs_inode_t *);
> +
>  /*
>   * helper function to extract extent size hint from inode
>   */
> @@ -1119,7 +1121,9 @@ xfs_bumplink(
>  {
>  	xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
>  
> -	ASSERT(ip->i_d.di_nlink > 0);
> +	if ((VFS_I(ip)->i_nlink == 0) &&
> +	    !(VFS_I(ip)->i_state & I_LINKABLE))
> +		ASSERT(ip->i_d.di_nlink > 0);
>  	ip->i_d.di_nlink++;
>  	inc_nlink(VFS_I(ip));
>  	if ((ip->i_d.di_version == 1) &&
> @@ -1473,6 +1477,7 @@ xfs_link(
>  {
>  	xfs_mount_t		*mp = tdp->i_mount;
>  	xfs_trans_t		*tp;
> +	struct xfs_trans_res	*tres;
>  	int			error;
>  	xfs_bmap_free_t         free_list;
>  	xfs_fsblock_t           first_block;
> @@ -1498,7 +1503,14 @@ xfs_link(
>  	tp = xfs_trans_alloc(mp, XFS_TRANS_LINK);
>  	cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
>  	resblks = XFS_LINK_SPACE_RES(mp, target_name->len);
> -	error = xfs_trans_reserve(tp, &M_RES(mp)->tr_link, resblks, 0);
> +
> +	if ((VFS_I(sip)->i_nlink == 0) &&
> +	    (VFS_I(sip)->i_state & I_LINKABLE))
> +		tres = &M_RES(mp)->tr_link_tmpfile;
> +	else
> +		tres = &M_RES(mp)->tr_link;
> +
> +	error = xfs_trans_reserve(tp, tres, resblks, 0);

Uggh. For the small amount of extra space needed for the unlinked
list reservation, I would simply add it to the tr_link reservation
and be done with it. That gets rid of the need for the noise here.

>  	if (error == ENOSPC) {
>  		resblks = 0;
>  		error = xfs_trans_reserve(tp, &M_RES(mp)->tr_link, 0, 0);
> @@ -1530,6 +1542,13 @@ xfs_link(
>  
>  	xfs_bmap_init(&free_list, &first_block);
>  
> +	if ((VFS_I(sip)->i_nlink == 0) &&
> +	    (VFS_I(sip)->i_state & I_LINKABLE)) {
> +		error = xfs_iunlink_remove(tp, sip);
> +		if (error)
> +			goto abort_return;
> +	}
> +
>  	error = xfs_dir_createname(tp, tdp, target_name, sip->i_ino,
>  					&first_block, &free_list, resblks);
>  	if (error)
> diff --git a/fs/xfs/xfs_trans_resv.c b/fs/xfs/xfs_trans_resv.c
> index f1eebe4..7c1234e 100644
> --- a/fs/xfs/xfs_trans_resv.c
> +++ b/fs/xfs/xfs_trans_resv.c
> @@ -228,6 +228,15 @@ xfs_calc_link_reservation(
>  				      XFS_FSB_TO_B(mp, 1))));
>  }
>  
> +STATIC uint
> +xfs_calc_link_tmpfile_reservation(
> +	struct xfs_mount        *mp)
> +{
> +	return xfs_calc_link_reservation(mp) +
> +		xfs_calc_buf_res(2, XFS_FSB_TO_B(mp, 1)) +
> +		xfs_calc_buf_res(2, mp->m_sb.sb_sectsize);
> +}

As per above, fold this into xfs_calc_link_reservation() by adding a:


		+ xfs_calc_iunlink_remove_resv(mp);

to the end of it.  Then you can also modify
xfs_calc_ifree_reservation() to use the same
xfs_calc_iunlink_remove_resv() function as well.

[ And similarly, looking back on the previous patch
xfs_calc_iunlink_add_resv can be used in xfs_calc_remove_reservation
so all the unlinked list manipulations are covered by the same
reservation calculations. ]

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  parent reply	other threads:[~2013-11-25 21:46 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-25 11:32 [RFC PATCH 0/4] xfs: add O_TMPFILE support Zhi Yong Wu
2013-11-25 11:32 ` [RFC PATCH 1/4] xfs: adjust the interface of xfs_qm_vop_dqalloc() Zhi Yong Wu
2013-11-25 13:43   ` Christoph Hellwig
2013-11-28  1:43     ` Zhi Yong Wu
2013-11-25 11:32 ` [RFC PATCH 2/4] xfs: add xfs_create_tmpfile() for O_TMPFILE support Zhi Yong Wu
2013-11-25 13:48   ` Christoph Hellwig
2013-11-28  1:48     ` Zhi Yong Wu
2013-11-25 21:36   ` Dave Chinner
2013-11-26  5:59     ` Christoph Hellwig
2013-11-28  2:41     ` Zhi Yong Wu
2013-11-25 11:32 ` [RFC PATCH 3/4] xfs: add a new method xfs_vn_tmpfile() Zhi Yong Wu
2013-11-25 13:48   ` Christoph Hellwig
2013-11-28  2:20     ` Zhi Yong Wu
2013-11-25 11:32 ` [RFC PATCH 4/4] xfs: allow linkat() on O_TMPFILE files Zhi Yong Wu
2013-11-25 13:51   ` Christoph Hellwig
2013-11-28  2:37     ` Zhi Yong Wu
2013-11-28 10:39       ` Christoph Hellwig
2013-11-28 10:47         ` Zhi Yong Wu
2013-11-25 21:46   ` Dave Chinner [this message]
2013-11-28  2:28     ` Zhi Yong Wu
2013-12-13 11:34     ` Zhi Yong Wu
2013-12-13 16:31       ` Christoph Hellwig
2013-11-28 10:35 ` [RFC PATCH 0/4] xfs: add O_TMPFILE support Christoph Hellwig
2013-11-28 10:50   ` Zhi Yong Wu
2013-11-28 14:39     ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131125214611.GI8803@dastard \
    --to=david@fromorbit.com \
    --cc=wuzhy@linux.vnet.ibm.com \
    --cc=xfs@oss.sgi.com \
    --cc=zwu.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox