Skip to contentSkip to conversation

xfs: add O_TMPFILE support

RFC PATCH In review Zhi Yong Wu 3 participants 25 messages Nov 25, 2013 – Dec 13, 2013 XFS filesystem

lore
Share & tools
lore
#0 lore raw

cover xfs: add O_TMPFILE support

From: Zhi Yong Wu <[email protected]>

HI, folks

The patchset is trying to add O_TMPFILE support to xfs. To make sure that it is going ahead in the right direction, although it is only one code draft, and hasn't strictly been tested, it is still post out ASAP.

For more information, please refer to Dave Chinner's RFD links:
1.) http://oss.sgi.com/archives/xfs/2013-08/msg00339.html
2.) http://oss.sgi.com/archives/xfs/2013-08/msg00336.html
3.) http://oss.sgi.com/archives/xfs/2013-08/msg00341.html

Any comments are appreciated, thanks.

Zhi Yong Wu (4):
xfs: adjust the interface of xfs_qm_vop_dqalloc()
xfs: add xfs_create_tmpfile() for O_TMPFILE support
xfs: add a new method xfs_vn_tmpfile()
xfs: allow linkat() on O_TMPFILE files

 fs/xfs/xfs_inode.c       |  154 +++++++++++++++++++++++++++++++++++++++++++++-
 fs/xfs/xfs_inode.h       |    2 +
 fs/xfs/xfs_ioctl.c       |    2 +-
 fs/xfs/xfs_iops.c        |   24 +++++++-
 fs/xfs/xfs_qm.c          |   50 +++++++++------
 fs/xfs/xfs_quota.h       |    6 +-
 fs/xfs/xfs_shared.h      |    4 +-
 fs/xfs/xfs_symlink.c     |    2 +-
 fs/xfs/xfs_trans_resv.c  |   48 ++++++++++++++
 fs/xfs/xfs_trans_resv.h  |    4 +
 fs/xfs/xfs_trans_space.h |    2 +
 11 files changed, 270 insertions(+), 28 deletions(-)
Signature · 6 lines
1.7.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw

RFC PATCH 1/4 xfs: adjust the interface of xfs_qm_vop_dqalloc()

From: Zhi Yong Wu <[email protected]>

There isn't a parent inode or a name for O_TMPFILE support, but will pass a struct xfs_mount to xfs_qm_vop_dqalloc(). So its interface need to be adjusted in order that O_TMPFILE creation function can also use it.

---
 fs/xfs/xfs_inode.c   |    2 +-
 fs/xfs/xfs_ioctl.c   |    2 +-
 fs/xfs/xfs_iops.c    |    3 ++-
 fs/xfs/xfs_qm.c      |   50 +++++++++++++++++++++++++++++++-------------------
 fs/xfs/xfs_quota.h   |    6 ++++--
 fs/xfs/xfs_symlink.c |    2 +-
 6 files changed, 40 insertions(+), 25 deletions(-)
fs/xfs/xfs_inode.c +1 -1
index 001aa89..1c23bdf 100644
@@ -1177,7 +1177,7 @@ xfs_create(
 	/*
 	 * Make sure that we have allocated dquot(s) on disk.
 	 */
-	error = xfs_qm_vop_dqalloc(dp, xfs_kuid_to_uid(current_fsuid()),
+	error = xfs_qm_vop_dqalloc(dp, mp, xfs_kuid_to_uid(current_fsuid()),
 					xfs_kgid_to_gid(current_fsgid()), prid,
 					XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
 					&udqp, &gdqp, &pdqp);
fs/xfs/xfs_ioctl.c +1 -1
index 4d61340..61abe32 100644
@@ -1089,7 +1089,7 @@ xfs_ioctl_setattr(
 	 * because the i_*dquot fields will get updated anyway.
 	 */
 	if (XFS_IS_QUOTA_ON(mp) && (mask & FSX_PROJID)) {
-		code = xfs_qm_vop_dqalloc(ip, ip->i_d.di_uid,
+		code = xfs_qm_vop_dqalloc(ip, ip->i_mount, ip->i_d.di_uid,
 					 ip->i_d.di_gid, fa->fsx_projid,
 					 XFS_QMOPT_PQUOTA, &udqp, NULL, &pdqp);
 		if (code)
fs/xfs/xfs_iops.c +2 -1
index 27e0e54..eb55be5 100644
@@ -540,7 +540,8 @@ xfs_setattr_nonsize(
 		 */
 		ASSERT(udqp == NULL);
 		ASSERT(gdqp == NULL);
-		error = xfs_qm_vop_dqalloc(ip, xfs_kuid_to_uid(uid),
+		error = xfs_qm_vop_dqalloc(ip, ip->i_mount,
+					   xfs_kuid_to_uid(uid),
 					   xfs_kgid_to_gid(gid),
 					   xfs_get_projid(ip),
 					   qflags, &udqp, &gdqp, NULL);
fs/xfs/xfs_qm.c +31 -19

122 lines not on this page · raw message

fs/xfs/xfs_quota.h +4 -2
index 5376dd4..c898ad2 100644
@@ -80,7 +80,8 @@ extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *,
 		struct xfs_mount *, struct xfs_dquot *,
 		struct xfs_dquot *, struct xfs_dquot *, long, long, uint);
 
-extern int xfs_qm_vop_dqalloc(struct xfs_inode *, xfs_dqid_t, xfs_dqid_t,
+extern int xfs_qm_vop_dqalloc(struct xfs_inode *, struct xfs_mount *,
+		xfs_dqid_t, xfs_dqid_t,
 		prid_t, uint, struct xfs_dquot **, struct xfs_dquot **,
 		struct xfs_dquot **);
 extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *,
@@ -103,7 +104,8 @@ extern void xfs_qm_unmount_quotas(struct xfs_mount *);
 
 #else
 static inline int
-xfs_qm_vop_dqalloc(struct xfs_inode *ip, xfs_dqid_t uid, xfs_dqid_t gid,
+xfs_qm_vop_dqalloc(struct xfs_inode *ip, struct xfs_mount *mp,
+		xfs_dqid_t uid, xfs_dqid_t gid,
 		prid_t prid, uint flags, struct xfs_dquot **udqp,
 		struct xfs_dquot **gdqp, struct xfs_dquot **pdqp)
 {
fs/xfs/xfs_symlink.c +1 -1
index 14e58f2..dcb26692 100644
@@ -216,7 +216,7 @@ xfs_symlink(
 	/*
 	 * Make sure that we have allocated dquot(s) on disk.
 	 */
-	error = xfs_qm_vop_dqalloc(dp,
+	error = xfs_qm_vop_dqalloc(dp, mp,
 			xfs_kuid_to_uid(current_fsuid()),
 			xfs_kgid_to_gid(current_fsgid()), prid,
 			XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
Signature · 6 lines
1.7.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#2 lore raw

Re: [RFC PATCH 1/4] xfs: adjust the interface of xfs_qm_vop_dqalloc()

Quoted 5 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

There isn't a parent inode or a name for O_TMPFILE support, but will pass a struct xfs_mount to xfs_qm_vop_dqalloc(). So its interface need to be adjusted in order that O_TMPFILE creation function can also use it.

Yes, there is. The tmpfile method gets the parent directory passed
as it's first argument.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw

Re: [RFC PATCH 1/4] xfs: adjust the interface of xfs_qm_vop_dqalloc()

Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

There isn't a parent inode or a name for O_TMPFILE support, but will pass a struct xfs_mount to xfs_qm_vop_dqalloc(). So its interface need to be adjusted in order that O_TMPFILE creation function can also use it.

Yes, there is. The tmpfile method gets the parent directory passed
as it's first argument.

ok, will pass it in.

Quoted 5 lines

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Signature · 8 lines
Regards,

Zhi Yong Wu

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#4 lore raw

RFC PATCH 2/4 xfs: add xfs_create_tmpfile() for O_TMPFILE support

In reply to Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

The function is used to create one O_TMPFILE file.

http://oss.sgi.com/archives/xfs/2013-08/msg00339.html

---
 fs/xfs/xfs_inode.c       |  129 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/xfs_inode.h       |    2 +
 fs/xfs/xfs_shared.h      |    4 +-
 fs/xfs/xfs_trans_resv.c  |   35 ++++++++++++
 fs/xfs/xfs_trans_resv.h  |    2 +
 fs/xfs/xfs_trans_space.h |    2 +
 6 files changed, 173 insertions(+), 1 deletions(-)
fs/xfs/xfs_inode.c +129 -0
index 1c23bdf..e1832de 100644
@@ -1337,6 +1337,135 @@ xfs_create(
 }
 
 int
+xfs_create_tmpfile(
+	xfs_mount_t		*mp,
+	umode_t			mode,
+	dev_t			rdev,
+	xfs_inode_t		**ipp)
+{
+	struct xfs_inode	*ip = NULL;
+	struct xfs_trans	*tp = NULL;
+	int			error;
+	uint			cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
+	struct xfs_dquot	*udqp = NULL;
+	struct xfs_dquot	*gdqp = NULL;
+	struct xfs_dquot	*pdqp = NULL;
+	struct xfs_trans_res	*tres;
+	uint			resblks;
+
+	if (XFS_FORCED_SHUTDOWN(mp))
+		return XFS_ERROR(EIO);
+
+	/*
+	 * Make sure that we have allocated dquot(s) on disk.
+	 */
+	error = xfs_qm_vop_dqalloc(NULL, mp, xfs_kuid_to_uid(current_fsuid()),
+					xfs_kgid_to_gid(current_fsgid()),
+					XFS_PROJID_DEFAULT,
+					XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
+					&udqp, &gdqp, &pdqp);
+	if (error)
+		return error;
+
+	resblks = XFS_CREATE_TMPFILE_SPACE_RES(mp);
+	tp = xfs_trans_alloc(mp, XFS_TRANS_CREATE_TMPFILE);
+
+	/*
+	 * Initially assume that the file does not exist and
+	 * reserve the resources for that case.  If that is not
+	 * the case we'll drop the one we have and get a more
+	 * appropriate transaction later.
+	 */
+	tres = &M_RES(mp)->tr_create_tmpfile;
+	error = xfs_trans_reserve(tp, tres, resblks, 0);
+	if (error == ENOSPC) {
+		/* flush outstanding delalloc blocks and retry */
+		xfs_flush_inodes(mp);
+		error = xfs_trans_reserve(tp, tres, resblks, 0);
+	}
+	if (error == ENOSPC) {
+		/* No space at all so try a "no-allocation" reservation */
+		resblks = 0;
+		error = xfs_trans_reserve(tp, tres, 0, 0);
+	}
+	if (error) {
+		cancel_flags = 0;
+		goto out_trans_cancel;
+	}
+
+	/*
+	 * Reserve disk quota and the inode.
+	 */
+	error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp,
+						pdqp, resblks, 1, 0);
+	if (error)
+		goto out_trans_cancel;
+
+	/*
+	 * A newly created regular or special file just has one directory
+	 * entry pointing to them, but a directory also the "." entry
+	 * pointing to itself.
+	 */
+	error = xfs_dir_ialloc(&tp, NULL, mode, 1, rdev,
+				XFS_PROJID_DEFAULT, resblks > 0,
+				&ip, NULL);
+	if (error) {
+		if (error == ENOSPC)
+			goto out_trans_cancel;
+		goto out_trans_abort;
+	}
+
+	/*
+	 * If this is a synchronous mount, make sure that the
+	 * create transaction goes to disk before returning to
+	 * the user.
+	 */
+	if (mp->m_flags & (XFS_MOUNT_WSYNC|XFS_MOUNT_DIRSYNC))
+		xfs_trans_set_sync(tp);
+
+	/*
+	 * Attach the dquot(s) to the inodes and modify them incore.
+	 * These ids of the inode couldn't have changed since the new
+	 * inode has been locked ever since it was created.
+	 */
+	xfs_qm_vop_create_dqattach(tp, ip, udqp, gdqp, pdqp);
+
+	error = xfs_iunlink(tp, ip);
+	if (error)
+		goto out_trans_abort;
+
+	error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
+	if (error)
+		goto out_release_inode;
+
+	xfs_qm_dqrele(udqp);
+	xfs_qm_dqrele(gdqp);
+	xfs_qm_dqrele(pdqp);
+
+	*ipp = ip;
+	return 0;
+
+ out_trans_abort:
+	cancel_flags |= XFS_TRANS_ABORT;
+ out_trans_cancel:
+	xfs_trans_cancel(tp, cancel_flags);
+ out_release_inode:
+	/*
+	 * Wait until after the current transaction is aborted to
+	 * release the inode.  This prevents recursive transactions
+	 * and deadlocks from xfs_inactive.
+	 */
+	if (ip)
+		IRELE(ip);
+
+	xfs_qm_dqrele(udqp);
+	xfs_qm_dqrele(gdqp);
+	xfs_qm_dqrele(pdqp);
+
+	return error;
+}
+
+int
 xfs_link(
 	xfs_inode_t		*tdp,
 	xfs_inode_t		*sip,
fs/xfs/xfs_inode.h +2 -0
index 9e6efccb..1f69fb3 100644
@@ -323,6 +323,8 @@ int		xfs_lookup(struct xfs_inode *dp, struct xfs_name *name,
 			   struct xfs_inode **ipp, struct xfs_name *ci_name);
 int		xfs_create(struct xfs_inode *dp, struct xfs_name *name,
 			   umode_t mode, xfs_dev_t rdev, struct xfs_inode **ipp);
+int		xfs_create_tmpfile(struct xfs_mount *mp, umode_t mode,
+			   xfs_dev_t rdev, struct xfs_inode **ipp);
 int		xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
 			   struct xfs_inode *ip);
 int		xfs_link(struct xfs_inode *tdp, struct xfs_inode *sip,
fs/xfs/xfs_shared.h +3 -1
index 8c5035a1..4484e51 100644
@@ -104,7 +104,8 @@ extern const struct xfs_buf_ops xfs_symlink_buf_ops;
 #define	XFS_TRANS_SB_COUNT		41
 #define	XFS_TRANS_CHECKPOINT		42
 #define	XFS_TRANS_ICREATE		43
-#define	XFS_TRANS_TYPE_MAX		43
+#define	XFS_TRANS_CREATE_TMPFILE	44
+#define	XFS_TRANS_TYPE_MAX		44
 /* new transaction types need to be reflected in xfs_logprint(8) */
 
 #define XFS_TRANS_TYPES \
@@ -112,6 +113,7 @@ extern const struct xfs_buf_ops xfs_symlink_buf_ops;
 	{ XFS_TRANS_SETATTR_SIZE,	"SETATTR_SIZE" }, \
 	{ XFS_TRANS_INACTIVE,		"INACTIVE" }, \
 	{ XFS_TRANS_CREATE,		"CREATE" }, \
+	{ XFS_TRANS_CREATE_TMPFILE,	"CREATE_TMPFILE" }, \
 	{ XFS_TRANS_CREATE_TRUNC,	"CREATE_TRUNC" }, \
 	{ XFS_TRANS_TRUNCATE_FILE,	"TRUNCATE_FILE" }, \
 	{ XFS_TRANS_REMOVE,		"REMOVE" }, \
fs/xfs/xfs_trans_resv.c +35 -0
index 2fd59c0..f1eebe4 100644
@@ -343,6 +343,36 @@ xfs_calc_create_reservation(
 
 }
 
+STATIC uint
+xfs_calc_icreate_tmpfile_reservation(xfs_mount_t *mp)
+{
+	return XFS_DQUOT_LOGRES(mp) +
+		xfs_calc_icreate_resv_alloc(mp) +
+		xfs_calc_inode_res(mp, 1) +
+		xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
+		xfs_calc_buf_res(2, mp->m_sb.sb_sectsize);
+}
+
+STATIC uint
+__xfs_calc_create_tmpfile_reservation(
+	struct xfs_mount	*mp)
+{
+	return XFS_DQUOT_LOGRES(mp) +
+		xfs_calc_create_resv_alloc(mp) +
+		xfs_calc_inode_res(mp, 1) +
+		xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
+		xfs_calc_buf_res(2, mp->m_sb.sb_sectsize);
+}
+
+STATIC uint
+xfs_calc_create_tmpfile_reservation(
+	struct xfs_mount        *mp)
+{
+	if (xfs_sb_version_hascrc(&mp->m_sb))
+		return xfs_calc_icreate_tmpfile_reservation(mp);
+	return __xfs_calc_create_tmpfile_reservation(mp);
+}
+
 /*
  * Making a new directory is the same as creating a new file.
  */
@@ -729,6 +759,11 @@ xfs_trans_resv_calc(
 	resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT;
 	resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
 
+	resp->tr_create_tmpfile.tr_logres =
+			xfs_calc_create_tmpfile_reservation(mp);
+	resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT;
+	resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+
 	resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
 	resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT;
 	resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
fs/xfs/xfs_trans_resv.h +2 -0
index de7de9a..285621d 100644
@@ -38,6 +38,7 @@ struct xfs_trans_resv {
 	struct xfs_trans_res	tr_remove;	/* unlink trans */
 	struct xfs_trans_res	tr_symlink;	/* symlink trans */
 	struct xfs_trans_res	tr_create;	/* create trans */
+	struct xfs_trans_res	tr_create_tmpfile; /* create O_TMPFILE trans */
 	struct xfs_trans_res	tr_mkdir;	/* mkdir trans */
 	struct xfs_trans_res	tr_ifree;	/* inode free trans */
 	struct xfs_trans_res	tr_ichange;	/* inode update trans */
@@ -100,6 +101,7 @@ struct xfs_trans_resv {
 #define	XFS_ITRUNCATE_LOG_COUNT		2
 #define XFS_INACTIVE_LOG_COUNT		2
 #define	XFS_CREATE_LOG_COUNT		2
+#define	XFS_CREATE_TMPFILE_LOG_COUNT	2
 #define	XFS_MKDIR_LOG_COUNT		3
 #define	XFS_SYMLINK_LOG_COUNT		3
 #define	XFS_REMOVE_LOG_COUNT		2
fs/xfs/xfs_trans_space.h +2 -0
index 7d2c920..16fba89 100644
@@ -61,6 +61,8 @@
 	(XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_B_TO_FSB(mp, v))
 #define	XFS_CREATE_SPACE_RES(mp,nl)	\
 	(XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
+#define	XFS_CREATE_TMPFILE_SPACE_RES(mp)	\
+	XFS_IALLOC_SPACE_RES(mp)
 #define	XFS_DIOSTRAT_SPACE_RES(mp, v)	\
 	(XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + (v))
 #define	XFS_GROWFS_SPACE_RES(mp)	\
Signature · 6 lines
1.7.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#5 lore raw

Re: [RFC PATCH 2/4] xfs: add xfs_create_tmpfile() for O_TMPFILE support

Quoted 17 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

The function is used to create one O_TMPFILE file.

http://oss.sgi.com/archives/xfs/2013-08/msg00339.html

---
 fs/xfs/xfs_inode.c       |  129 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/xfs_inode.h       |    2 +
 fs/xfs/xfs_shared.h      |    4 +-
 fs/xfs/xfs_trans_resv.c  |   35 ++++++++++++
 fs/xfs/xfs_trans_resv.h  |    2 +
 fs/xfs/xfs_trans_space.h |    2 +
 6 files changed, 173 insertions(+), 1 deletions(-)

int

fs/xfs/xfs_inode.c xfs_create( · line 1344

Quoted 5 lines
fs/xfs/xfs_inode.c +5 -0
+xfs_create_tmpfile(
+	xfs_mount_t		*mp,
+	umode_t			mode,
+	dev_t			rdev,
+	xfs_inode_t		**ipp)

Please use struct xfs_mount and struct xfs_inode for any new code.

fs/xfs/xfs_inode.c xfs_create( · line 1378

Quoted 6 lines
fs/xfs/xfs_inode.c +6 -0
+	/*
+	 * Initially assume that the file does not exist and
+	 * reserve the resources for that case.  If that is not
+	 * the case we'll drop the one we have and get a more
+	 * appropriate transaction later.
+	 */

I can't see how this comment makes any sense.

fs/xfs/xfs_inode.c xfs_create( · line 1390

Quoted 12 lines
fs/xfs/xfs_inode.c +12 -0
+	tres = &M_RES(mp)->tr_create_tmpfile;
+	error = xfs_trans_reserve(tp, tres, resblks, 0);
+	if (error == ENOSPC) {
+		/* flush outstanding delalloc blocks and retry */
+		xfs_flush_inodes(mp);
+		error = xfs_trans_reserve(tp, tres, resblks, 0);
+	}
+	if (error == ENOSPC) {
+		/* No space at all so try a "no-allocation" reservation */
+		resblks = 0;
+		error = xfs_trans_reserve(tp, tres, 0, 0);
+	}

Please factor this into a new xfs_trans_reserver_create helper (better names welcome of course).
similar.

fs/xfs/xfs_inode.c xfs_create( · line 1398

Quoted 3 lines
fs/xfs/xfs_inode.c +3 -0
+	/*
+	 * Reserve disk quota and the inode.
+	 */

I don't think that comment adds a whole lot of value. (Same for the other quota comment above).

fs/xfs/xfs_inode.c xfs_create( · line 1408

Quoted 5 lines
fs/xfs/xfs_inode.c +5 -0
+	/*
+	 * A newly created regular or special file just has one directory
+	 * entry pointing to them, but a directory also the "." entry
+	 * pointing to itself.
+	 */

Given that we only create regular files here the comment can be removed.

Quoted 19 lines
fs/xfs/xfs_trans_resv.c +18 -0
+STATIC uint
+xfs_calc_icreate_tmpfile_reservation(xfs_mount_t *mp)
+{
+	return XFS_DQUOT_LOGRES(mp) +
+		xfs_calc_icreate_resv_alloc(mp) +
+		xfs_calc_inode_res(mp, 1) +
+		xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
+		xfs_calc_buf_res(2, mp->m_sb.sb_sectsize);
+}
+
+STATIC uint
+__xfs_calc_create_tmpfile_reservation(
+	struct xfs_mount	*mp)
+{
+	return XFS_DQUOT_LOGRES(mp) +
+		xfs_calc_create_resv_alloc(mp) +
+		xfs_calc_inode_res(mp, 1) +
+		xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +

fs/xfs/xfs_trans_resv.c xfs_calc_create_reservation( · line 373

Quoted 10 lines
fs/xfs/xfs_trans_resv.c +10 -0
+		xfs_calc_buf_res(2, mp->m_sb.sb_sectsize);
+}
+
+STATIC uint
+xfs_calc_create_tmpfile_reservation(
+	struct xfs_mount        *mp)
+{
+	if (xfs_sb_version_hascrc(&mp->m_sb))
+		return xfs_calc_icreate_tmpfile_reservation(mp);
+	return __xfs_calc_create_tmpfile_reservation(mp);

Shouldn't we name this xfs_calc_create_tmpfile_reservation_v4 and _v5 or no postix and _crc? Either way the double underscore naming looks confusing.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#6 lore raw

Re: [RFC PATCH 2/4] xfs: add xfs_create_tmpfile() for O_TMPFILE support

OK, will fix or cleanup all the comments, thanks.

Quoted 92 lines · Christoph Hellwig
Quoted 17 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

The function is used to create one O_TMPFILE file.

http://oss.sgi.com/archives/xfs/2013-08/msg00339.html

---
 fs/xfs/xfs_inode.c       |  129 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/xfs_inode.h       |    2 +
 fs/xfs/xfs_shared.h      |    4 +-
 fs/xfs/xfs_trans_resv.c  |   35 ++++++++++++
 fs/xfs/xfs_trans_resv.h  |    2 +
 fs/xfs/xfs_trans_space.h |    2 +
 6 files changed, 173 insertions(+), 1 deletions(-)

int

fs/xfs/xfs_inode.c xfs_create( · line 1344

Quoted 5 lines
fs/xfs/xfs_inode.c +5 -0
+xfs_create_tmpfile(
+     xfs_mount_t             *mp,
+     umode_t                 mode,
+     dev_t                   rdev,
+     xfs_inode_t             **ipp)

Please use struct xfs_mount and struct xfs_inode for any new code.

fs/xfs/xfs_inode.c xfs_create( · line 1378

Quoted 6 lines
fs/xfs/xfs_inode.c +6 -0
+     /*
+      * Initially assume that the file does not exist and
+      * reserve the resources for that case.  If that is not
+      * the case we'll drop the one we have and get a more
+      * appropriate transaction later.
+      */

I can't see how this comment makes any sense.

fs/xfs/xfs_inode.c xfs_create( · line 1390

Quoted 12 lines
fs/xfs/xfs_inode.c +12 -0
+     tres = &M_RES(mp)->tr_create_tmpfile;
+     error = xfs_trans_reserve(tp, tres, resblks, 0);
+     if (error == ENOSPC) {
+             /* flush outstanding delalloc blocks and retry */
+             xfs_flush_inodes(mp);
+             error = xfs_trans_reserve(tp, tres, resblks, 0);
+     }
+     if (error == ENOSPC) {
+             /* No space at all so try a "no-allocation" reservation */
+             resblks = 0;
+             error = xfs_trans_reserve(tp, tres, 0, 0);
+     }

Please factor this into a new xfs_trans_reserver_create helper (better names welcome of course).
similar.

fs/xfs/xfs_inode.c xfs_create( · line 1398

Quoted 3 lines
fs/xfs/xfs_inode.c +3 -0
+     /*
+      * Reserve disk quota and the inode.
+      */

I don't think that comment adds a whole lot of value. (Same for the other quota comment above).

fs/xfs/xfs_inode.c xfs_create( · line 1408

Quoted 5 lines
fs/xfs/xfs_inode.c +5 -0
+     /*
+      * A newly created regular or special file just has one directory
+      * entry pointing to them, but a directory also the "." entry
+      * pointing to itself.
+      */

Given that we only create regular files here the comment can be removed.

Quoted 25 lines
fs/xfs/xfs_trans_resv.c +24 -0
+STATIC uint
+xfs_calc_icreate_tmpfile_reservation(xfs_mount_t *mp)
+{
+     return XFS_DQUOT_LOGRES(mp) +
+             xfs_calc_icreate_resv_alloc(mp) +
+             xfs_calc_inode_res(mp, 1) +
+             xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
+             xfs_calc_buf_res(2, mp->m_sb.sb_sectsize);
+}
+
+STATIC uint
+__xfs_calc_create_tmpfile_reservation(
+     struct xfs_mount        *mp)
+{
+     return XFS_DQUOT_LOGRES(mp) +
+             xfs_calc_create_resv_alloc(mp) +
+             xfs_calc_inode_res(mp, 1) +
+             xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
+             xfs_calc_buf_res(2, mp->m_sb.sb_sectsize);
+}
+
+STATIC uint
+xfs_calc_create_tmpfile_reservation(
+     struct xfs_mount        *mp)
Quoted 8 lines

fs/xfs/xfs_trans_resv.c xfs_calc_create_reservation( · line 373

Quoted 4 lines
fs/xfs/xfs_trans_resv.c +4 -0
+{
+     if (xfs_sb_version_hascrc(&mp->m_sb))
+             return xfs_calc_icreate_tmpfile_reservation(mp);
+     return __xfs_calc_create_tmpfile_reservation(mp);

Shouldn't we name this xfs_calc_create_tmpfile_reservation_v4 and _v5 or no postix and _crc? Either way the double underscore naming looks confusing.

It follows up with the current naming style of regular file reservation functions.
After we adopt Dave's suggestion, this issue will disappear.

Quoted 1 line
Signature · 8 lines
Regards,

Zhi Yong Wu

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#7 lore raw

Re: [RFC PATCH 2/4] xfs: add xfs_create_tmpfile() for O_TMPFILE support

In reply to Zhi Yong Wu
Quoted 43 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

The function is used to create one O_TMPFILE file.

http://oss.sgi.com/archives/xfs/2013-08/msg00339.html

---
 fs/xfs/xfs_inode.c       |  129 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/xfs_inode.h       |    2 +
 fs/xfs/xfs_shared.h      |    4 +-
 fs/xfs/xfs_trans_resv.c  |   35 ++++++++++++
 fs/xfs/xfs_trans_resv.h  |    2 +
 fs/xfs/xfs_trans_space.h |    2 +
 6 files changed, 173 insertions(+), 1 deletions(-)
fs/xfs/xfs_inode.c +19 -0
index 1c23bdf..e1832de 100644
@@ -1337,6 +1337,135 @@ xfs_create(
 }
 
 int
+xfs_create_tmpfile(
+	xfs_mount_t		*mp,
+	umode_t			mode,
+	dev_t			rdev,
+	xfs_inode_t		**ipp)
+{
+	struct xfs_inode	*ip = NULL;
+	struct xfs_trans	*tp = NULL;
+	int			error;
+	uint			cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
+	struct xfs_dquot	*udqp = NULL;
+	struct xfs_dquot	*gdqp = NULL;
+	struct xfs_dquot	*pdqp = NULL;
+	struct xfs_trans_res	*tres;
+	uint			resblks;
+
+	if (XFS_FORCED_SHUTDOWN(mp))
+		return XFS_ERROR(EIO);
+

fs/xfs/xfs_inode.c xfs_create( · line 1368

Quoted 10 lines
fs/xfs/xfs_inode.c +10 -0
+	/*
+	 * Make sure that we have allocated dquot(s) on disk.
+	 */
+	error = xfs_qm_vop_dqalloc(NULL, mp, xfs_kuid_to_uid(current_fsuid()),
+					xfs_kgid_to_gid(current_fsgid()),
+					XFS_PROJID_DEFAULT,
+					XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
+					&udqp, &gdqp, &pdqp);
+	if (error)
+		return error;

Is XFS_PROJID_DEFAULT correct here? If we are getting a parent inode from ->tmpfile, then this should be handled the same way as for xfs_create.

Quoted 16 lines
fs/xfs/xfs_inode.c +16 -0
+
+	resblks = XFS_CREATE_TMPFILE_SPACE_RES(mp);
+	tp = xfs_trans_alloc(mp, XFS_TRANS_CREATE_TMPFILE);
+
+	/*
+	 * Initially assume that the file does not exist and
+	 * reserve the resources for that case.  If that is not
+	 * the case we'll drop the one we have and get a more
+	 * appropriate transaction later.
+	 */
+	tres = &M_RES(mp)->tr_create_tmpfile;
+	error = xfs_trans_reserve(tp, tres, resblks, 0);
+	if (error == ENOSPC) {
+		/* flush outstanding delalloc blocks and retry */
+		xfs_flush_inodes(mp);
+		error = xfs_trans_reserve(tp, tres, resblks, 0);

fs/xfs/xfs_inode.c xfs_create( · line 1394

Quoted 10 lines
fs/xfs/xfs_inode.c +10 -0
+	}
+	if (error == ENOSPC) {
+		/* No space at all so try a "no-allocation" reservation */
+		resblks = 0;
+		error = xfs_trans_reserve(tp, tres, 0, 0);
+	}
+	if (error) {
+		cancel_flags = 0;
+		goto out_trans_cancel;
+	}

I don't think this is necessary here. The ENOSPC flushing in xfs_create() is done to ensure we have space for directory block creation, not so much for inode allocation. Hence it doesn't make a lot of sense to have this here....

Quoted 19 lines
fs/xfs/xfs_inode.c +19 -0
+	/*
+	 * Reserve disk quota and the inode.
+	 */
+	error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp,
+						pdqp, resblks, 1, 0);
+	if (error)
+		goto out_trans_cancel;
+
+	/*
+	 * A newly created regular or special file just has one directory
+	 * entry pointing to them, but a directory also the "." entry
+	 * pointing to itself.
+	 */
+	error = xfs_dir_ialloc(&tp, NULL, mode, 1, rdev,
+				XFS_PROJID_DEFAULT, resblks > 0,
+				&ip, NULL);
+	if (error) {
+		if (error == ENOSPC)
+			goto out_trans_cancel;

fs/xfs/xfs_inode.c xfs_create( · line 1424

Quoted 10 lines
fs/xfs/xfs_inode.c +10 -0
+		goto out_trans_abort;
+	}
+
+	/*
+	 * If this is a synchronous mount, make sure that the
+	 * create transaction goes to disk before returning to
+	 * the user.
+	 */
+	if (mp->m_flags & (XFS_MOUNT_WSYNC|XFS_MOUNT_DIRSYNC))
+		xfs_trans_set_sync(tp);

I'm not sure that XFS_MOUNT_DIRSYNC shoul dbe checked here, as there is no directory operations to synchronise at all...

Quoted 10 lines
fs/xfs/xfs_inode.c +10 -0
+STATIC uint
+xfs_calc_icreate_tmpfile_reservation(xfs_mount_t *mp)
+{
+	return XFS_DQUOT_LOGRES(mp) +
+		xfs_calc_icreate_resv_alloc(mp) +
+		xfs_calc_inode_res(mp, 1) +
+		xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
+		xfs_calc_buf_res(2, mp->m_sb.sb_sectsize);
+}
+

fs/xfs/xfs_inode.c xfs_create( · line 1443

Quoted 10 lines
fs/xfs/xfs_inode.c +10 -0
+STATIC uint
+__xfs_calc_create_tmpfile_reservation(
+	struct xfs_mount	*mp)
+{
+	return XFS_DQUOT_LOGRES(mp) +
+		xfs_calc_create_resv_alloc(mp) +
+		xfs_calc_inode_res(mp, 1) +
+		xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
+		xfs_calc_buf_res(2, mp->m_sb.sb_sectsize);
+}

What exactly is being modified here? All of the other reservations have comments explaining what each of the individual components of the reservation are. Yes, I can see that there's an inode, a filesystem block and 2 sectors being reserved, but what are they?

It's also double counting the XFS_DQUOT_LOGRES(), as they are accounted for in xfs_calc_[i]create_reservation().

Also, the directory create reservations are broken up into two components - the inode allocation and the common directory name creation component, and so the tmpfile reservation should probably be broken up the same way. i.e this:

fs/xfs/xfs_inode.c xfs_create( · line 1452

Quoted 9 lines
fs/xfs/xfs_inode.c +9 -0
+
+STATIC uint
+xfs_calc_create_tmpfile_reservation(
+	struct xfs_mount        *mp)
+{
+	if (xfs_sb_version_hascrc(&mp->m_sb))
+		return xfs_calc_icreate_tmpfile_reservation(mp);
+	return __xfs_calc_create_tmpfile_reservation(mp);
+}

Could simply be:

STATIC uint
xfs_calc_create_tmpfile_reservation(
struct xfs_mount *mp)

{
	uint	res;

	if (xfs_sb_version_hascrc(&mp->m_sb))
		res = xfs_calc_icreate_resv_alloc(mp);
	else
		res = xfs_calc_create_resv_alloc(mp);
	return res + xfs_calc_iunlink_add_resv(mp);
}

fs/xfs/xfs_trans_space.h line 65

Quoted 10 lines
fs/xfs/xfs_trans_space.h +2 -0
index 7d2c920..16fba89 100644
@@ -61,6 +61,8 @@
 	(XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_B_TO_FSB(mp, v))
 #define	XFS_CREATE_SPACE_RES(mp,nl)	\
 	(XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
+#define	XFS_CREATE_TMPFILE_SPACE_RES(mp)	\
+	XFS_IALLOC_SPACE_RES(mp)

I wouldn't bother with this macro - just use XFS_IALLOC_SPACE_RES() directly.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#8 lore raw

Re: [RFC PATCH 2/4] xfs: add xfs_create_tmpfile() for O_TMPFILE support

Quoted 4 lines · Dave Chinner

Is XFS_PROJID_DEFAULT correct here? If we are getting a parent inode from ->tmpfile, then this should be handled the same way as for xfs_create.

It should. And while we're at it that code from create and symlink should be factored into:

static inline projid_t xfs_initial_projid(struct xfs_inode *dp)

{
	 if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)
	 	return xfs_get_projid(dp);
	return XFS_PROJID_DEFAULT;
}

fist.

Quoted 4 lines

I don't think this is necessary here. The ENOSPC flushing in xfs_create() is done to ensure we have space for directory block creation, not so much for inode allocation. Hence it doesn't make a lot of sense to have this here....

Point. I take back my earlier comment that it should be factored.

Quoted 2 lines

I'm not sure that XFS_MOUNT_DIRSYNC shoul dbe checked here, as there is no directory operations to synchronise at all...

It probably shouldn't indeed. Reminds me of my old patch to make this a flag to xfs_trans_commit instead of all that boilerplate code..

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#9 lore raw

Re: [RFC PATCH 2/4] xfs: add xfs_create_tmpfile() for O_TMPFILE support

In reply to Dave Chinner
Quoted 50 lines · Dave Chinner
Quoted 49 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

The function is used to create one O_TMPFILE file.

http://oss.sgi.com/archives/xfs/2013-08/msg00339.html

---
 fs/xfs/xfs_inode.c       |  129 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/xfs_inode.h       |    2 +
 fs/xfs/xfs_shared.h      |    4 +-
 fs/xfs/xfs_trans_resv.c  |   35 ++++++++++++
 fs/xfs/xfs_trans_resv.h  |    2 +
 fs/xfs/xfs_trans_space.h |    2 +
 6 files changed, 173 insertions(+), 1 deletions(-)
fs/xfs/xfs_inode.c +25 -0
index 1c23bdf..e1832de 100644
@@ -1337,6 +1337,135 @@ xfs_create(
 }
 
 int
+xfs_create_tmpfile(
+     xfs_mount_t             *mp,
+     umode_t                 mode,
+     dev_t                   rdev,
+     xfs_inode_t             **ipp)
+{
+     struct xfs_inode        *ip = NULL;
+     struct xfs_trans        *tp = NULL;
+     int                     error;
+     uint                    cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
+     struct xfs_dquot        *udqp = NULL;
+     struct xfs_dquot        *gdqp = NULL;
+     struct xfs_dquot        *pdqp = NULL;
+     struct xfs_trans_res    *tres;
+     uint                    resblks;
+
+     if (XFS_FORCED_SHUTDOWN(mp))
+             return XFS_ERROR(EIO);
+
+     /*
+      * Make sure that we have allocated dquot(s) on disk.
+      */
+     error = xfs_qm_vop_dqalloc(NULL, mp, xfs_kuid_to_uid(current_fsuid()),
+                                     xfs_kgid_to_gid(current_fsgid()),
+                                     XFS_PROJID_DEFAULT,
Quoted 8 lines

fs/xfs/xfs_inode.c xfs_create( · line 1368

Quoted 4 lines
fs/xfs/xfs_inode.c +4 -0
+                                     XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
+                                     &udqp, &gdqp, &pdqp);
+     if (error)
+             return error;

Is XFS_PROJID_DEFAULT correct here? If we are getting a parent inode from ->tmpfile, then this should be handled the same way as for xfs_create.

ok, will fix it.

Quoted 24 lines
Quoted 24 lines
fs/xfs/xfs_inode.c +23 -0
+
+     resblks = XFS_CREATE_TMPFILE_SPACE_RES(mp);
+     tp = xfs_trans_alloc(mp, XFS_TRANS_CREATE_TMPFILE);
+
+     /*
+      * Initially assume that the file does not exist and
+      * reserve the resources for that case.  If that is not
+      * the case we'll drop the one we have and get a more
+      * appropriate transaction later.
+      */
+     tres = &M_RES(mp)->tr_create_tmpfile;
+     error = xfs_trans_reserve(tp, tres, resblks, 0);
+     if (error == ENOSPC) {
+             /* flush outstanding delalloc blocks and retry */
+             xfs_flush_inodes(mp);
+             error = xfs_trans_reserve(tp, tres, resblks, 0);
+     }
+     if (error == ENOSPC) {
+             /* No space at all so try a "no-allocation" reservation */
+             resblks = 0;
+             error = xfs_trans_reserve(tp, tres, 0, 0);
+     }
+     if (error) {
Quoted 8 lines

fs/xfs/xfs_inode.c xfs_create( · line 1394

Quoted 3 lines
fs/xfs/xfs_inode.c +3 -0
+             cancel_flags = 0;
+             goto out_trans_cancel;
+     }

I don't think this is necessary here. The ENOSPC flushing in xfs_create() is done to ensure we have space for directory block creation, not so much for inode allocation. Hence it doesn't make a lot of sense to have this here....

Good explaination, will fix it, thanks.

Quoted 25 lines
Quoted 25 lines
fs/xfs/xfs_inode.c +24 -0
+     /*
+      * Reserve disk quota and the inode.
+      */
+     error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp,
+                                             pdqp, resblks, 1, 0);
+     if (error)
+             goto out_trans_cancel;
+
+     /*
+      * A newly created regular or special file just has one directory
+      * entry pointing to them, but a directory also the "." entry
+      * pointing to itself.
+      */
+     error = xfs_dir_ialloc(&tp, NULL, mode, 1, rdev,
+                             XFS_PROJID_DEFAULT, resblks > 0,
+                             &ip, NULL);
+     if (error) {
+             if (error == ENOSPC)
+                     goto out_trans_cancel;
+             goto out_trans_abort;
+     }
+
+     /*
+      * If this is a synchronous mount, make sure that the
Quoted 8 lines

fs/xfs/xfs_inode.c xfs_create( · line 1424

Quoted 5 lines
fs/xfs/xfs_inode.c +5 -0
+      * create transaction goes to disk before returning to
+      * the user.
+      */
+     if (mp->m_flags & (XFS_MOUNT_WSYNC|XFS_MOUNT_DIRSYNC))
+             xfs_trans_set_sync(tp);

I'm not sure that XFS_MOUNT_DIRSYNC shoul dbe checked here, as there is no directory operations to synchronise at all...

ok, will fix it.

Quoted 18 lines
Quoted 18 lines
fs/xfs/xfs_inode.c +17 -0
+STATIC uint
+xfs_calc_icreate_tmpfile_reservation(xfs_mount_t *mp)
+{
+     return XFS_DQUOT_LOGRES(mp) +
+             xfs_calc_icreate_resv_alloc(mp) +
+             xfs_calc_inode_res(mp, 1) +
+             xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
+             xfs_calc_buf_res(2, mp->m_sb.sb_sectsize);
+}
+
+STATIC uint
+__xfs_calc_create_tmpfile_reservation(
+     struct xfs_mount        *mp)
+{
+     return XFS_DQUOT_LOGRES(mp) +
+             xfs_calc_create_resv_alloc(mp) +
+             xfs_calc_inode_res(mp, 1) +
Quoted 8 lines

fs/xfs/xfs_inode.c xfs_create( · line 1443

Quoted 3 lines
fs/xfs/xfs_inode.c +3 -0
+             xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
+             xfs_calc_buf_res(2, mp->m_sb.sb_sectsize);
+}

What exactly is being modified here? All of the other reservations have comments explaining what each of the individual components of the reservation are. Yes, I can see that there's an inode, a filesystem block and 2 sectors being reserved, but what are they?

Will add some comments in next version.

Quoted 3 lines

It's also double counting the XFS_DQUOT_LOGRES(), as they are accounted for in xfs_calc_[i]create_reservation().

I don't understand why you said it double counts XFS_DQUOT_LOGRES()? i only see it is counted once. Can you say more details?

Quoted 21 lines

Also, the directory create reservations are broken up into two components - the inode allocation and the common directory name creation component, and so the tmpfile reservation should probably be broken up the same way. i.e this:

fs/xfs/xfs_inode.c xfs_create( · line 1452

Quoted 9 lines
fs/xfs/xfs_inode.c +9 -0
+
+STATIC uint
+xfs_calc_create_tmpfile_reservation(
+     struct xfs_mount        *mp)
+{
+     if (xfs_sb_version_hascrc(&mp->m_sb))
+             return xfs_calc_icreate_tmpfile_reservation(mp);
+     return __xfs_calc_create_tmpfile_reservation(mp);
+}

Could simply be:

STATIC uint
xfs_calc_create_tmpfile_reservation(
struct xfs_mount *mp)

Quoted 9 lines
{
        uint    res;

        if (xfs_sb_version_hascrc(&mp->m_sb))
                res = xfs_calc_icreate_resv_alloc(mp);
        else
                res = xfs_calc_create_resv_alloc(mp);
        return res + xfs_calc_iunlink_add_resv(mp);
}

Good suggestion, will apply this.

Quoted 15 lines

fs/xfs/xfs_trans_space.h line 65

Quoted 12 lines
fs/xfs/xfs_trans_space.h +2 -0
index 7d2c920..16fba89 100644
@@ -61,6 +61,8 @@
      (XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_B_TO_FSB(mp, v))
 #define      XFS_CREATE_SPACE_RES(mp,nl)     \
      (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
+#define      XFS_CREATE_TMPFILE_SPACE_RES(mp)        \
+     XFS_IALLOC_SPACE_RES(mp)

I wouldn't bother with this macro - just use XFS_IALLOC_SPACE_RES() directly.

ok, will remove this macro.

Quoted 7 lines

Cheers,

Dave.
--
Dave Chinner
[email protected]

Signature · 8 lines
Regards,

Zhi Yong Wu

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#10 lore raw

RFC PATCH 3/4 xfs: add a new method xfs_vn_tmpfile()

In reply to Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

Add a new O_TMPFILE method to VFS inteface.

http://oss.sgi.com/archives/xfs/2013-08/msg00336.html

---
 fs/xfs/xfs_iops.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
fs/xfs/xfs_iops.c +21 -0
index eb55be5..5d2e781 100644
@@ -39,6 +39,7 @@
 #include "xfs_da_btree.h"
 #include "xfs_dir2_priv.h"
 #include "xfs_dinode.h"
+#include "xfs_trans_space.h"
 
 #include <linux/capability.h>
 #include <linux/xattr.h>
@@ -1051,6 +1052,24 @@ xfs_vn_fiemap(
 	return 0;
 }
 
+STATIC int
+xfs_vn_tmpfile(
+	struct inode	*dir,
+	struct dentry	*dentry,
+	umode_t		mode)
+{
+	struct xfs_inode *ip = NULL;
+	int		error;
+
+	error = xfs_create_tmpfile(XFS_I(dir)->i_mount, mode, 0, &ip);
+	if (error)
+		return -error;
+
+	d_instantiate(dentry, VFS_I(ip));
+
+	return -error;
+}
+
 static const struct inode_operations xfs_inode_operations = {
 	.get_acl		= xfs_get_acl,
 	.getattr		= xfs_vn_getattr,
@@ -1087,6 +1106,7 @@ static const struct inode_operations xfs_dir_inode_operations = {
 	.removexattr		= generic_removexattr,
 	.listxattr		= xfs_vn_listxattr,
 	.update_time		= xfs_vn_update_time,
+	.tmpfile		= xfs_vn_tmpfile,
 };
 
 static const struct inode_operations xfs_dir_ci_inode_operations = {
@@ -1113,6 +1133,7 @@ static const struct inode_operations xfs_dir_ci_inode_operations = {
 	.removexattr		= generic_removexattr,
 	.listxattr		= xfs_vn_listxattr,
 	.update_time		= xfs_vn_update_time,
+	.tmpfile		= xfs_vn_tmpfile,
 };
 
 static const struct inode_operations xfs_symlink_inode_operations = {
Signature · 6 lines
1.7.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#12 lore raw

Re: [RFC PATCH 3/4] xfs: add a new method xfs_vn_tmpfile()

Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

Add a new O_TMPFILE method to VFS inteface.

Looks reasonable except that you should pass on the parent inode.

ok, will do as this.

Quoted 1 line
Signature · 8 lines
Regards,

Zhi Yong Wu

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#13 lore raw

RFC PATCH 4/4 xfs: allow linkat() on O_TMPFILE files

In reply to Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

Enable O_TMPFILE support in linkat().

http://oss.sgi.com/archives/xfs/2013-08/msg00341.html

---
 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(-)
fs/xfs/xfs_inode.c +21 -2
index e1832de..7ab029b 100644
@@ -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);
 	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)
fs/xfs/xfs_trans_resv.c +13 -0
index f1eebe4..7c1234e 100644
@@ -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);
+}
+
 /*
  * For removing a directory entry we can modify:
  *    the parent directory inode: inode size
@@ -747,6 +756,10 @@ xfs_trans_resv_calc(
 	resp->tr_link.tr_logcount = XFS_LINK_LOG_COUNT;
 	resp->tr_link.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
 
+	resp->tr_link_tmpfile.tr_logres = xfs_calc_link_tmpfile_reservation(mp);
+	resp->tr_link_tmpfile.tr_logcount = XFS_LINK_TMPFILE_LOG_COUNT;
+	resp->tr_link_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+
 	resp->tr_remove.tr_logres = xfs_calc_remove_reservation(mp);
 	resp->tr_remove.tr_logcount = XFS_REMOVE_LOG_COUNT;
 	resp->tr_remove.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
fs/xfs/xfs_trans_resv.h +2 -0
index 285621d..86a0daf 100644
@@ -35,6 +35,7 @@ struct xfs_trans_resv {
 	struct xfs_trans_res	tr_itruncate;	/* truncate trans */
 	struct xfs_trans_res	tr_rename;	/* rename trans */
 	struct xfs_trans_res	tr_link;	/* link trans */
+	struct xfs_trans_res	tr_link_tmpfile; /* link O_TMPFILE trans */
 	struct xfs_trans_res	tr_remove;	/* unlink trans */
 	struct xfs_trans_res	tr_symlink;	/* symlink trans */
 	struct xfs_trans_res	tr_create;	/* create trans */
@@ -106,6 +107,7 @@ struct xfs_trans_resv {
 #define	XFS_SYMLINK_LOG_COUNT		3
 #define	XFS_REMOVE_LOG_COUNT		2
 #define	XFS_LINK_LOG_COUNT		2
+#define	XFS_LINK_TMPFILE_LOG_COUNT	2
 #define	XFS_RENAME_LOG_COUNT		2
 #define	XFS_WRITE_LOG_COUNT		2
 #define	XFS_ADDAFORK_LOG_COUNT		2
Signature · 6 lines
1.7.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#14 lore raw

Re: [RFC PATCH 4/4] xfs: allow linkat() on O_TMPFILE files

fs/xfs/xfs_inode.c xfs_bumplink( · line 1126

Quoted 4 lines
fs/xfs/xfs_inode.c +3 -1
-	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);
	ASSERT(ip->i_d.di_nlink > 0 || (VFS_I(ip)->i_state & I_LINKABLE));

fs/xfs/xfs_inode.c xfs_link( · line 1511

Quoted 11 lines
fs/xfs/xfs_inode.c +6 -1
@@ -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;

Just check i_nlink, and for consistency it might make sense to just use the xfs_inode one. The VFS already made sure we don't inodes with I_LINKABLE and a zero link count.

fs/xfs/xfs_inode.c xfs_link( · line 1546

Quoted 2 lines
fs/xfs/xfs_inode.c +2 -0
+	if ((VFS_I(sip)->i_nlink == 0) &&
+	    (VFS_I(sip)->i_state & I_LINKABLE)) {

Same here.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#15 lore raw

Re: [RFC PATCH 4/4] xfs: allow linkat() on O_TMPFILE files

Quoted 6 lines · Christoph Hellwig

fs/xfs/xfs_inode.c xfs_bumplink( · line 1126

Quoted 4 lines
fs/xfs/xfs_inode.c +3 -1
-     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);
        ASSERT(ip->i_d.di_nlink > 0 || (VFS_I(ip)->i_state & I_LINKABLE));

This is wrong, and it should be

          ASSERT(ip->i_d.di_nlink > 0 || !(VFS_I(ip)->i_state & I_LINKABLE));
Quoted 15 lines

fs/xfs/xfs_inode.c xfs_link( · line 1511

Quoted 12 lines
fs/xfs/xfs_inode.c +6 -1
@@ -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;

Just check i_nlink, and for consistency it might make sense to just use the xfs_inode one. The VFS already made sure we don't inodes with

but struct xfs_inode has no stuff similar to i_nlink....

Quoted 1 line

I_LINKABLE and a zero link count.

No, pls see the chunk of code:
int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
{
...

    /* Make sure we don't allow creating hardlink to an unlinked file */
    if (inode->i_nlink == 0 && !(inode->i_state & I_LINKABLE))
        error =  -ENOENT;
    else if (max_links && inode->i_nlink >= max_links)
        error = -EMLINK;
    else
        error = dir->i_op->link(old_dentry, dir, new_dentry);

    if (!error && (inode->i_state & I_LINKABLE)) {
        spin_lock(&inode->i_lock);
        inode->i_state &= ~I_LINKABLE;
        spin_unlock(&inode->i_lock);
    }

...
}

When xfs_link() is called, I_LINKABLE flag isn't cleared.

Quoted 6 lines

fs/xfs/xfs_inode.c xfs_link( · line 1546

Quoted 3 lines
fs/xfs/xfs_inode.c +2 -0
+     if ((VFS_I(sip)->i_nlink == 0) &&
+         (VFS_I(sip)->i_state & I_LINKABLE)) {

Same here.

Signature · 8 lines
Regards,

Zhi Yong Wu

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#16 lore raw

Re: [RFC PATCH 4/4] xfs: allow linkat() on O_TMPFILE files

Quoted 9 lines · Zhi Yong Wu
Quoted 6 lines · Christoph Hellwig

fs/xfs/xfs_inode.c xfs_bumplink( · line 1126

Quoted 4 lines
fs/xfs/xfs_inode.c +3 -1
-     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);
        ASSERT(ip->i_d.di_nlink > 0 || (VFS_I(ip)->i_state & I_LINKABLE));

This is wrong, and it should be

          ASSERT(ip->i_d.di_nlink > 0 || !(VFS_I(ip)->i_state & I_LINKABLE));

Why we want to assrrt that either the link count is bigger than 0, or that the I_LINKABLE flag is set (for files created using O_TMPFILE)

Quoted 10 lines
Quoted 9 lines

fs/xfs/xfs_inode.c xfs_link( · line 1511

Quoted 6 lines
fs/xfs/xfs_inode.c +6 -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;

Just check i_nlink, and for consistency it might make sense to just use the xfs_inode one. The VFS already made sure we don't inodes with

but struct xfs_inode has no stuff similar to i_nlink....

ip->i_d.di_nlink is the equivalent.

Quoted 9 lines
Quoted 1 line

I_LINKABLE and a zero link count.

No, pls see the chunk of code:
int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
{
...

    /* Make sure we don't allow creating hardlink to an unlinked file */
    if (inode->i_nlink == 0 && !(inode->i_state & I_LINKABLE))
        error =  -ENOENT;

This makes sure we never created a link if the count is zero unless the I_LINKABLE is set, so we'll never see a zero link count without I_LINKABLE.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#17 lore raw

Re: [RFC PATCH 4/4] xfs: allow linkat() on O_TMPFILE files

You are right for both following cases, and will fix them, thanks.

Quoted 41 lines · Christoph Hellwig
Quoted 9 lines · Zhi Yong Wu
Quoted 6 lines · Christoph Hellwig

fs/xfs/xfs_inode.c xfs_bumplink( · line 1126

Quoted 4 lines
fs/xfs/xfs_inode.c +3 -1
-     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);
        ASSERT(ip->i_d.di_nlink > 0 || (VFS_I(ip)->i_state & I_LINKABLE));

This is wrong, and it should be

          ASSERT(ip->i_d.di_nlink > 0 || !(VFS_I(ip)->i_state & I_LINKABLE));

Why we want to assrrt that either the link count is bigger than 0, or that the I_LINKABLE flag is set (for files created using O_TMPFILE)

Quoted 10 lines
Quoted 9 lines

fs/xfs/xfs_inode.c xfs_link( · line 1511

Quoted 6 lines
fs/xfs/xfs_inode.c +6 -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;

Just check i_nlink, and for consistency it might make sense to just use the xfs_inode one. The VFS already made sure we don't inodes with

but struct xfs_inode has no stuff similar to i_nlink....

ip->i_d.di_nlink is the equivalent.

Quoted 9 lines
Quoted 1 line

I_LINKABLE and a zero link count.

No, pls see the chunk of code:
int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
{
...

    /* Make sure we don't allow creating hardlink to an unlinked file */
    if (inode->i_nlink == 0 && !(inode->i_state & I_LINKABLE))
        error =  -ENOENT;

This makes sure we never created a link if the count is zero unless the I_LINKABLE is set, so we'll never see a zero link count without I_LINKABLE.

Signature · 8 lines
Regards,

Zhi Yong Wu

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#18 lore raw

Re: [RFC PATCH 4/4] xfs: allow linkat() on O_TMPFILE files

In reply to Zhi Yong Wu
Quoted 48 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

Enable O_TMPFILE support in linkat().

http://oss.sgi.com/archives/xfs/2013-08/msg00341.html

---
 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(-)
fs/xfs/xfs_inode.c +6 -1
index e1832de..7ab029b 100644
@@ -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;

fs/xfs/xfs_inode.c xfs_link( · line 1513

Quoted 10 lines
fs/xfs/xfs_inode.c +8 -1
 	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.

Quoted 23 lines
fs/xfs/xfs_inode.c +7 -0
 	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)
fs/xfs/xfs_trans_resv.c +0 -0
index f1eebe4..7c1234e 100644
@@ -228,6 +228,15 @@ xfs_calc_link_reservation(
 				      XFS_FSB_TO_B(mp, 1))));

fs/xfs/xfs_trans_resv.c xfs_calc_link_reservation( · line 238

Quoted 10 lines
fs/xfs/xfs_trans_resv.c +8 -0
 }
 
+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.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#19 lore raw

Re: [RFC PATCH 4/4] xfs: allow linkat() on O_TMPFILE files

Quoted 55 lines · Dave Chinner
Quoted 54 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

Enable O_TMPFILE support in linkat().

http://oss.sgi.com/archives/xfs/2013-08/msg00341.html

---
 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(-)
fs/xfs/xfs_inode.c +10 -2
index e1832de..7ab029b 100644
@@ -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;
Quoted 8 lines

fs/xfs/xfs_inode.c xfs_link( · line 1513

Quoted 4 lines
fs/xfs/xfs_inode.c +4 -0
+     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.

will apply this.

Quoted 40 lines
Quoted 24 lines
fs/xfs/xfs_inode.c +7 -0
      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)
fs/xfs/xfs_trans_resv.c +0 -0
index f1eebe4..7c1234e 100644
@@ -228,6 +228,15 @@ xfs_calc_link_reservation(
                                    XFS_FSB_TO_B(mp, 1))));

fs/xfs/xfs_trans_resv.c xfs_calc_link_reservation( · line 238

Quoted 10 lines
fs/xfs/xfs_trans_resv.c +8 -0
 }
 
+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);

Quoted 8 lines

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. ]

Good suggestion, will try to apply them in next version, thanks.

Quoted 7 lines

Cheers,

Dave.
--
Dave Chinner
[email protected]

Signature · 8 lines
Regards,

Zhi Yong Wu

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#20 lore raw

Re: [RFC PATCH 4/4] xfs: allow linkat() on O_TMPFILE files

In reply to Dave Chinner
Quoted 65 lines · Dave Chinner
Quoted 48 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

Enable O_TMPFILE support in linkat().

http://oss.sgi.com/archives/xfs/2013-08/msg00341.html

---
 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(-)
fs/xfs/xfs_inode.c +6 -1
index e1832de..7ab029b 100644
@@ -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;

fs/xfs/xfs_inode.c xfs_link( · line 1513

Quoted 10 lines
fs/xfs/xfs_inode.c +8 -1
      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.

Quoted 4 lines

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

+ xfs_calc_iunlink_remove_resv(mp);

This way seems to not work...
In xfs_calc_link_reservation(), How to determine if it is for one regular file or O_TMPFILE file? since this functions is only passed in mp?

Quoted 16 lines

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
[email protected]

Signature · 8 lines
Regards,

Zhi Yong Wu

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#21 lore raw

Re: [RFC PATCH 4/4] xfs: allow linkat() on O_TMPFILE files

Quoted 5 lines · Zhi Yong Wu
Quoted 5 lines

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.

Quoted 8 lines
Quoted 4 lines

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

+ xfs_calc_iunlink_remove_resv(mp);

This way seems to not work...
In xfs_calc_link_reservation(), How to determine if it is for one regular file or O_TMPFILE file? since this functions is only passed in mp?

The way I understand Dave above is that you should always reserve the higher amount.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#22 lore raw
In reply to Zhi Yong Wu
Quoted 7 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

HI, folks

The patchset is trying to add O_TMPFILE support to xfs. To make sure that it is going ahead in the right direction, although it is only one code draft, and hasn't strictly been tested, it is still post out ASAP.

Btw, for the real submission we need proper xfstests coverage, I can't really believe how the other filesystems added it without QA coverage :(

Besides the obvious test programs there's a reproducer for a a simple bug already in commit dda5690defe4af62ee120f055e98e40d97e4c760 in the kernel tree.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#23 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Zhi Yong Wu

From: Zhi Yong Wu <[email protected]>

HI, folks

The patchset is trying to add O_TMPFILE support to xfs. To make sure that it is going ahead in the right direction, although it is only one code draft, and hasn't strictly been tested, it is still post out ASAP.

Btw, for the real submission we need proper xfstests coverage, I can't

ok, i will try to run xfstests before real submission is done.

Quoted 1 line

really believe how the other filesystems added it without QA coverage :(

heh, i guess that you should ask those fs maintainers this question.

Quoted 4 lines

Besides the obvious test programs there's a reproducer for a a simple bug already in commit dda5690defe4af62ee120f055e98e40d97e4c760 in the kernel tree.

ok, will test if this bug is triggered.

Quoted 1 line
Signature · 8 lines
Regards,

Zhi Yong Wu

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs