xfs: add O_TMPFILE support
Subsystems (2)
cover xfs: add O_TMPFILE support
From: Zhi Yong Wu <[email protected]>
HI, folks
It's time to post out the first formal version, welcome to any constructive comment, thanks.
If anyone is interested in playing with it, you can get this patchset from my dev git on github:
git://github.com/wuzhy/kernel.git xfs_tmpfile
The patchset was tests agaist the code snippet from Andy Lutomirski and other test cases:
http://lwn.net/Articles/562296/
If you have any other better test cases, please let me know, thanks.
#include <stdio.h>
#include <err.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define __O_TMPFILE 020000000
#define O_DIRECTORY 0200000
#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
#define AT_EMPTY_PATH 0x1000
int main(int argc, char **argv)
{
char buf[128];
if (argc != 3)
errx(1, "Usage: flinktest PATH linkat|proc");
int fd = open(".", O_TMPFILE | O_RDWR, 0600);
if (fd == -1)
err(1, "O_TMPFILE");
else
printf("fd #: %d\n", fd);
write(fd, "test", 4);
if (!strcmp(argv[2], "linkat")) {
if (linkat(fd, "", AT_FDCWD, argv[1], AT_EMPTY_PATH) != 0)
err(1, "linkat");
} else if (!strcmp(argv[2], "proc")) {
sprintf(buf, "/proc/self/fd/%d", fd);
if (linkat(AT_FDCWD, buf, AT_FDCWD, argv[1], AT_SYMLINK_FOLLOW) != 0)
err(1, "linkat");
} else {
errx(1, "invalid mode");
} return 0;
}
Changelog from rfc:
- Addressed the comments from Dave Chinner and Christoph Hellwig.
Zhi Yong Wu (5):
xfs: factor prid related codes into xfs_get_initial_prid()
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 | 142 ++++++++++++++++++++++++++++++++++++++++++++--- fs/xfs/xfs_inode.h | 2 + fs/xfs/xfs_ioctl.c | 2 +- fs/xfs/xfs_iops.c | 25 ++++++++- 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 | 51 +++++++++++++++++ fs/xfs/xfs_trans_resv.h | 4 + 10 files changed, 255 insertions(+), 33 deletions(-)
Signature · 1 line
1.7.6.5
PATCH 1/5 xfs: factor prid related codes into xfs_get_initial_prid()
From: Zhi Yong Wu <[email protected]>
It will be reused by the O_TMPFILE creation function.
--- fs/xfs/xfs_inode.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)
fs/xfs/xfs_inode.c +9 -4
@@ -1139,6 +1139,14 @@ xfs_bumplink(return 0 ; } +static inline prid_t xfs_get_initial_prid (struct xfs_inode *dp) +{ +if (dp->i_d.di_flags &XFS_DIFLAG_PROJINHERIT ) +return xfs_get_projid (dp); +else +return XFS_PROJID_DEFAULT ; +} + int xfs_create( xfs_inode_t *dp,
@@ -1169,10 +1177,7 @@ xfs_create(if (XFS_FORCED_SHUTDOWN (mp))return XFS_ERROR (EIO ); -if (dp->i_d.di_flags &XFS_DIFLAG_PROJINHERIT ) - prid =xfs_get_projid (dp); -else - prid =XFS_PROJID_DEFAULT ; + prid =xfs_get_initial_prid (dp);/* * Make sure that we have allocated dquot(s) on disk.
Signature · 6 lines
1.7.6.5 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 1/5] xfs: factor prid related codes into xfs_get_initial_prid()
fs/xfs/xfs_inode.c xfs_bumplink( · line 1148
Quoted 7 lines
fs/xfs/xfs_inode.c +7
-0+static inline prid_t xfs_get_initial_prid (struct xfs_inode *dp) +{ +if (dp->i_d.di_flags &XFS_DIFLAG_PROJINHERIT ) +return xfs_get_projid (dp); +else +return XFS_PROJID_DEFAULT ; +}
You could skip the else here.
Otherwise looks good,
Re: [PATCH 1/5] xfs: factor prid related codes into xfs_get_initial_prid()
Quoted 9 lines · Christoph Hellwig
fs/xfs/xfs_inode.c xfs_bumplink( · line 1148
Quoted 7 lines
fs/xfs/xfs_inode.c +7
-0+static inline prid_t xfs_get_initial_prid (struct xfs_inode *dp) +{ +if (dp->i_d.di_flags &XFS_DIFLAG_PROJINHERIT ) +return xfs_get_projid (dp); +else +return XFS_PROJID_DEFAULT ; +}You could skip the else here.
Except that, I'd suggest we move this helper to proper header file with further refactoring in xfs_symlink(), and it could be a separate patch.
Thanks,
-Jeff
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 1/5] xfs: factor prid related codes into xfs_get_initial_prid()
Quoted 10 lines · Jeff Liu
Quoted 9 lines · Christoph Hellwig
fs/xfs/xfs_inode.c xfs_bumplink( · line 1148
Quoted 7 lines
fs/xfs/xfs_inode.c +7
-0+static inline prid_t xfs_get_initial_prid (struct xfs_inode *dp) +{ +if (dp->i_d.di_flags &XFS_DIFLAG_PROJINHERIT ) +return xfs_get_projid (dp); +else +return XFS_PROJID_DEFAULT ; +}You could skip the else here.
Quoted 2 lines
Except that, I'd suggest we move this helper to proper header file with further refactoring in
xfs_symlink(), and it could be a separate patch.
Good point, will apply it, thanks.
Quoted 3 lines
Thanks,
-Jeff
Signature · 8 lines
Regards, Zhi Yong Wu _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 2/5 xfs: adjust the interface of xfs_qm_vop_dqalloc()
In reply to Zhi Yong WuFrom: Zhi Yong Wu <[email protected]>
There may be not 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
@@ -1182,7 +1182,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
@@ -1090,7 +1090,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
@@ -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
@@ -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
@@ -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
Re: [PATCH 2/5] xfs: adjust the interface of xfs_qm_vop_dqalloc()
Quoted 7 lines · Zhi Yong Wu
From: Zhi Yong Wu <[email protected]>
There may be not a parent inode or a name for
O_TMPFILEsupport, but will pass a structxfs_mounttoxfs_qm_vop_dqalloc(). So its interface need to be adjusted in order thatO_TMPFILEcreation function can also use it.Signed-off-by Zhi Yong Wu <[email protected]>
This patch is not actually needed, as we do get passed a parent.
Re: [PATCH 2/5] xfs: adjust the interface of xfs_qm_vop_dqalloc()
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Zhi Yong Wu
From: Zhi Yong Wu <[email protected]>
There may be not a parent inode or a name for
O_TMPFILEsupport, but will pass a structxfs_mounttoxfs_qm_vop_dqalloc(). So its interface need to be adjusted in order thatO_TMPFILEcreation function can also use it.Signed-off-by Zhi Yong Wu <[email protected]>This patch is not actually needed, as we do get passed a parent.
Discarded, thanks.
Quoted 1 line
Signature · 8 lines
Regards, Zhi Yong Wu _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 3/5 xfs: add xfs_create_tmpfile() for O_TMPFILE support
In reply to Zhi Yong WuFrom: Zhi Yong Wu <[email protected]>
The function is used to create one O_TMPFILE file. For more info, please refer to:
http://oss.sgi.com/archives/xfs/2013-08/msg00339.html
--- fs/xfs/xfs_inode.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_inode.h | 2 + fs/xfs/xfs_shared.h | 4 +- fs/xfs/xfs_trans_resv.c | 31 ++++++++++++++ fs/xfs/xfs_trans_resv.h | 2 + 5 files changed, 144 insertions(+), 1 deletions(-)
fs/xfs/xfs_inode.c +106 -0
@@ -1342,6 +1342,112 @@ xfs_create( }int +xfs_create_tmpfile ( +struct xfs_inode *dp, +struct xfs_mount *mp, +umode_t mode, +dev_t rdev, +struct xfs_inode **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 (dp, mp,xfs_kuid_to_uid (current_fsuid ()), +xfs_kgid_to_gid (current_fsgid ()), +xfs_get_initial_prid (dp), +XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , + &udqp, &gdqp, &pdqp); +if (error) +return error; + + resblks =XFS_IALLOC_SPACE_RES (mp); + tp =xfs_trans_alloc (mp,XFS_TRANS_CREATE_TMPFILE ); + + tres = &M_RES (mp)->tr_create_tmpfile; + 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; + } + + error =xfs_trans_reserve_quota (tp, mp, udqp, gdqp, + pdqp, resblks,1 ,0 ); +if (error) + goto out_trans_cancel; + + error =xfs_dir_ialloc (&tp,NULL , mode,0 , rdev, +XFS_PROJID_DEFAULT , resblks >0 , + &ip,NULL ); +if (error) { +if (error ==ENOSPC ) + goto out_trans_cancel; + goto out_trans_abort; + } + +if (mp->m_flags &XFS_MOUNT_WSYNC ) +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
@@ -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_inode *dp,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
@@ -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 +31 -0
@@ -344,6 +344,32 @@ xfs_calc_create_reservation( }/* +* For adding an inode to unlinked list we can modify: +* the agi hash list: sector size +* the unlinked inode: inode size +*/ +STATIC uint +xfs_calc_iunlink_add_reservation (xfs_mount_t *mp) +{ +return xfs_calc_buf_res (1 , mp->m_sb.sb_sectsize) + +xfs_calc_inode_res (mp,1 ); +} + +STATIC uint +xfs_calc_create_tmpfile_reservation ( +struct xfs_mount *mp) +{ +uint res =XFS_DQUOT_LOGRES (mp); + +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_reservation (mp); +} + +/* * Making a new directory is the same as creating a new file. */ STATIC uint
@@ -729,6 +755,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
@@ -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
Signature · 1 line
1.7.6.5
Re: [PATCH 3/5] xfs: add xfs_create_tmpfile() for O_TMPFILE support
fs/xfs/xfs_inode.c xfs_create( · line 1396
Quoted 1 line
fs/xfs/xfs_inode.c +1
-0+ error = xfs_dir_ialloc(&tp, NULL, mode, 0, rdev,
please pass the parent inode pointer here.
fs/xfs/xfs_inode.c xfs_create( · line 1397
Quoted 1 line
fs/xfs/xfs_inode.c +1
-0+ XFS_PROJID_DEFAULT, resblks > 0,
and pass the project id that you inherited from the parent here.
Re: [PATCH 3/5] xfs: add xfs_create_tmpfile() for O_TMPFILE support
Fixed them, thanks.
Quoted 8 lines · Christoph Hellwig
Quoted 1 line
+ error = xfs_dir_ialloc(&tp, NULL, mode, 0, rdev,
please pass the parent inode pointer here.
Quoted 1 line
+
XFS_PROJID_DEFAULT, resblks > 0,and pass the project id that you inherited from the parent here.
Signature · 8 lines
Regards, Zhi Yong Wu _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 4/5 xfs: add a new method xfs_vn_tmpfile()
In reply to Zhi Yong WuFrom: Zhi Yong Wu <[email protected]>
Add a new O_TMPFILE method to VFS inteface.
For more info, please refer to:
http://oss.sgi.com/archives/xfs/2013-08/msg00336.html
--- fs/xfs/xfs_iops.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
fs/xfs/xfs_iops.c +22 -0
@@ -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,25 @@ 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),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 +1107,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 +1134,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 · 1 line
1.7.6.5
Re: [PATCH 4/5] xfs: add a new method xfs_vn_tmpfile()
Quoted 27 lines · Zhi Yong Wu
From: Zhi Yong Wu <[email protected]>
Add a new
O_TMPFILEmethod to VFS inteface.
For more info, please refer to:
http://oss.sgi.com/archives/xfs/2013-08/msg00336.htmlSigned-off-by Zhi Yong Wu <[email protected]>--- fs/xfs/xfs_iops.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)fs/xfs/xfs_iops.c +1
-0@@ -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,25 @@ xfs_vn_fiemap(return 0 ; }
fs/xfs/xfs_iops.c xfs_vn_fiemap( · line 1064
Quoted 10 lines
fs/xfs/xfs_iops.c +10
-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), XFS_I(dir)->i_mount,
No need to pass in the mount point here, the client can get it easily.
fs/xfs/xfs_iops.c xfs_vn_fiemap( · line 1065
Quoted 1 line
fs/xfs/xfs_iops.c +1
-0+ mode, 0, &ip);
Also no need for an always-zero argument.
fs/xfs/xfs_iops.c xfs_vn_fiemap( · line 1069
Quoted 4 lines
fs/xfs/xfs_iops.c +4
-0+if (error) +return -error; + +d_instantiate (dentry,VFS_I (ip));
Shouldn't this be a call to d_tmpfile() instead?
Also I'd suggest mergin this into the previous patch, so that we have one that actually adds O_TMPFILE support, and once place to write a nice good changelog.
Re: [PATCH 4/5] xfs: add a new method xfs_vn_tmpfile()
Quoted 41 lines · Christoph Hellwig
Quoted 27 lines · Zhi Yong Wu
From: Zhi Yong Wu <[email protected]>
Add a new
O_TMPFILEmethod to VFS inteface.
For more info, please refer to:
http://oss.sgi.com/archives/xfs/2013-08/msg00336.htmlSigned-off-by Zhi Yong Wu <[email protected]>--- fs/xfs/xfs_iops.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)fs/xfs/xfs_iops.c +1
-0@@ -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,25 @@ xfs_vn_fiemap(return 0 ; }fs/xfs/xfs_iops.c xfs_vn_fiemap( · line 1064
Quoted 10 lines
fs/xfs/xfs_iops.c +10
-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), XFS_I(dir)->i_mount,No need to pass in the mount point here, the client can get it easily.
Quoted 3 lines
fs/xfs/xfs_iops.c xfs_vn_fiemap( · line 1065
Quoted 1 line
fs/xfs/xfs_iops.c +1
-0+ mode, 0, &ip);Also no need for an always-zero argument.
Fixed, thanks.
Quoted 7 lines
fs/xfs/xfs_iops.c xfs_vn_fiemap( · line 1069
Quoted 5 lines
fs/xfs/xfs_iops.c +4
-0+if (error) +return -error; + +d_instantiate (dentry,VFS_I (ip));Shouldn't this be a call to
d_tmpfile()instead?
Yes, then it need to be called in xfs_create_tmpfile() just before xfs_iunlink() is called.
Quoted 3 lines
Also I'd suggest mergin this into the previous patch, so that we have one that actually adds
O_TMPFILEsupport, and once place to write a nice
Merged them, thanks.
Quoted 1 line
good changelog.
Signature · 8 lines
Regards, Zhi Yong Wu _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 5/5 xfs: allow linkat() on O_TMPFILE files
In reply to Zhi Yong WuFrom: Zhi Yong Wu <[email protected]>
Enable O_TMPFILE support in linkat().
For more info, please refer to:
http://oss.sgi.com/archives/xfs/2013-08/msg00341.html
--- fs/xfs/xfs_inode.c | 21 ++++++++++++++++++--- fs/xfs/xfs_trans_resv.c | 20 ++++++++++++++++++++ fs/xfs/xfs_trans_resv.h | 2 ++ 3 files changed, 40 insertions(+), 3 deletions(-)
fs/xfs/xfs_inode.c +18 -3
@@ -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,7 @@ xfs_bumplink( {xfs_trans_ichgtime (tp, ip,XFS_ICHGTIME_CHG ); -ASSERT (ip->i_d.di_nlink >0 ); +ASSERT (ip->i_d.di_nlink >0 || (VFS_I (ip)->i_state &I_LINKABLE )); ip->i_d.di_nlink++;inc_nlink (VFS_I (ip)); if ((ip->i_d.di_version == 1) &&
@@ -1455,6 +1457,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;
@@ -1480,10 +1483,16 @@ 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 (sip->i_d.di_nlink ==0 ) + 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 ); + error =xfs_trans_reserve (tp, tres,0 ,0 ); }if (error) { cancel_flags =0 ;
@@ -1512,6 +1521,12 @@ xfs_link(xfs_bmap_init (&free_list, &first_block); +if (sip->i_d.di_nlink ==0 ) { + 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 +20 -0
@@ -228,6 +228,22 @@ xfs_calc_link_reservation( XFS_FSB_TO_B(mp, 1)))); } +/* For creating a link to an O_TMPFILE inode, except modifying +* those metadata for regular inode, we still need to remove an inode +* from unlinked list at first. That is, we can modify: +* the agi hash list and counters: sector size +* the on disk inode before ours in the agi hash list: inode cluster size +*/ +STATIC uint +xfs_calc_link_tmpfile_reservation ( +struct xfs_mount *mp) +{ +return xfs_calc_link_reservation (mp) + +xfs_calc_buf_res (1 , mp->m_sb.sb_sectsize) + +MAX ((__uint16_t )XFS_FSB_TO_B (mp,1 ), + (__uint16_t )XFS_INODE_CLUSTER_SIZE (mp)); +} +/* * For removing a directory entry we can modify: * the parent directory inode: inode size
@@ -743,6 +759,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
@@ -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 · 1 line
1.7.6.5
Re: [PATCH 5/5] xfs: allow linkat() on O_TMPFILE files
Quoted 5 lines · Zhi Yong Wu
From: Zhi Yong Wu <[email protected]>
Enable
O_TMPFILEsupport inlinkat().
For more info, please refer to:
http://oss.sgi.com/archives/xfs/2013-08/msg00341.html
Generall you should provide all reasonable information in the changelog instead of linking to it.
fs/xfs/xfs_inode.c xfs_link( · line 1490
Quoted 4 lines
fs/xfs/xfs_inode.c +4
-0+if (sip->i_d.di_nlink ==0 ) + tres = &M_RES (mp)->tr_link_tmpfile; +else + tres = &M_RES (mp)->tr_link;
As mentioned before I think Dave wanted you to always use the same reservation, but I'll leave that discussion to him.
Quoted 6 lines
+/* For creating a link to an
O_TMPFILEinode, except modifying
+ * those metadata for regular inode, we still need to remove an inode
+ * from unlinked list at first. That is, we can modify:
+ * the agi hash list and counters: sector size
+ * the on disk inode before ours in the agi hash list: inode cluster size
+ */
We always have an emptry content
/*
line at the beginning of comments in XFS and the Linux kernel in general.
Re: [PATCH 5/5] xfs: allow linkat() on O_TMPFILE files
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Zhi Yong Wu
From: Zhi Yong Wu <[email protected]>
Enable
O_TMPFILEsupport inlinkat().
For more info, please refer to:
http://oss.sgi.com/archives/xfs/2013-08/msg00341.htmlGenerall you should provide all reasonable information in the changelog instead of linking to it.
will apply this, thanks.
Quoted 8 lines
fs/xfs/xfs_inode.c xfs_link( · line 1490
Quoted 5 lines
fs/xfs/xfs_inode.c +4
-0+if (sip->i_d.di_nlink ==0 ) + tres = &M_RES (mp)->tr_link_tmpfile; +else + tres = &M_RES (mp)->tr_link;As mentioned before I think Dave wanted you to always use the same reservation, but I'll leave that discussion to him.
If as you said, when some tons of regular files are created, it won't waste some disk space? e.g. some files want to reserve some space, but get NOSPACE due to other files reserving additional space?
Quoted 9 lines
Quoted 7 lines
+/* For creating a link to an
O_TMPFILEinode, except modifying
+ * those metadata for regular inode, we still need to remove an inode
+ * from unlinked list at first. That is, we can modify:
+ * the agi hash list and counters: sector size
+ * the on disk inode before ours in the agi hash list: inode cluster size
+ */We always have an emptry content
Done, thanks.
Quoted 6 lines
/*
line at the beginning of comments in XFS and the Linux kernel in general.
Signature · 8 lines
Regards, Zhi Yong Wu _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 5/5] xfs: allow linkat() on O_TMPFILE files
Quoted 17 lines · Zhi Yong Wu
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Zhi Yong Wu
From: Zhi Yong Wu <[email protected]>
Enable
O_TMPFILEsupport inlinkat().
For more info, please refer to:
http://oss.sgi.com/archives/xfs/2013-08/msg00341.htmlGenerall you should provide all reasonable information in the changelog instead of linking to it.
will apply this, thanks.
Quoted 6 lines
Quoted 5 lines
fs/xfs/xfs_inode.c +4
-0+if (sip->i_d.di_nlink ==0 ) + tres = &M_RES (mp)->tr_link_tmpfile; +else + tres = &M_RES (mp)->tr_link;
Quoted 5 lines
Quoted 2 lines
As mentioned before I think Dave wanted you to always use the same reservation, but I'll leave that discussion to him.
If as you said, when some tons of regular files are created, it won't waste some disk space? e.g. some files want to reserve some space, but get NOSPACE due to other files reserving additional space?
This is a log space reservation, not a disk space reservation. End either way, what is unused by the transaction is returned to the free space pool at the end of the transaction. So for simplicity, we should just use the one reservation for the link transaction - take whichever is larger at calculation time.
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 5/5] xfs: allow linkat() on O_TMPFILE files
Quoted 24 lines · Dave Chinner
Quoted 17 lines · Zhi Yong Wu
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Zhi Yong Wu
From: Zhi Yong Wu <[email protected]>
Enable
O_TMPFILEsupport inlinkat().
For more info, please refer to:
http://oss.sgi.com/archives/xfs/2013-08/msg00341.htmlGenerall you should provide all reasonable information in the changelog instead of linking to it.
will apply this, thanks.
Quoted 6 lines
Quoted 5 lines
fs/xfs/xfs_inode.c +4
-0+if (sip->i_d.di_nlink ==0 ) + tres = &M_RES (mp)->tr_link_tmpfile; +else + tres = &M_RES (mp)->tr_link;Quoted 5 lines
Quoted 2 lines
As mentioned before I think Dave wanted you to always use the same reservation, but I'll leave that discussion to him.
If as you said, when some tons of regular files are created, it won't waste some disk space? e.g. some files want to reserve some space, but get NOSPACE due to other files reserving additional space?
Quoted 5 lines
This is a log space reservation, not a disk space reservation. End either way, what is unused by the transaction is returned to the free space pool at the end of the transaction. So for simplicity, we should just use the one reservation for the link transaction - take whichever is larger at calculation time.
Good explaination, thanks Dave and Christoph. By the way, can you help check if the log reservation for adding/removing one inode to/from unlinked list is correct? or will you check after i post next version out?
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