xfs_iops.c (549c7297717c32ee53f156cd949e055e601f67bb) | xfs_iops.c (f736d93d76d3e97d6986c6d26c8eaa32536ccc5c) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (c) 2000-2005 Silicon Graphics, Inc. 4 * All Rights Reserved. 5 */ 6#include "xfs.h" 7#include "xfs_fs.h" 8#include "xfs_shared.h" --- 114 unchanged lines hidden (view full) --- 123 */ 124 xfs_dentry_to_name(&teardown, dentry); 125 126 xfs_remove(XFS_I(dir), &teardown, XFS_I(inode)); 127} 128 129STATIC int 130xfs_generic_create( | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (c) 2000-2005 Silicon Graphics, Inc. 4 * All Rights Reserved. 5 */ 6#include "xfs.h" 7#include "xfs_fs.h" 8#include "xfs_shared.h" --- 114 unchanged lines hidden (view full) --- 123 */ 124 xfs_dentry_to_name(&teardown, dentry); 125 126 xfs_remove(XFS_I(dir), &teardown, XFS_I(inode)); 127} 128 129STATIC int 130xfs_generic_create( |
131 struct user_namespace *mnt_userns, |
|
131 struct inode *dir, 132 struct dentry *dentry, 133 umode_t mode, 134 dev_t rdev, 135 bool tmpfile) /* unnamed file */ 136{ 137 struct inode *inode; 138 struct xfs_inode *ip = NULL; --- 17 unchanged lines hidden (view full) --- 156 return error; 157 158 /* Verify mode is valid also for tmpfile case */ 159 error = xfs_dentry_mode_to_name(&name, dentry, mode); 160 if (unlikely(error)) 161 goto out_free_acl; 162 163 if (!tmpfile) { | 132 struct inode *dir, 133 struct dentry *dentry, 134 umode_t mode, 135 dev_t rdev, 136 bool tmpfile) /* unnamed file */ 137{ 138 struct inode *inode; 139 struct xfs_inode *ip = NULL; --- 17 unchanged lines hidden (view full) --- 157 return error; 158 159 /* Verify mode is valid also for tmpfile case */ 160 error = xfs_dentry_mode_to_name(&name, dentry, mode); 161 if (unlikely(error)) 162 goto out_free_acl; 163 164 if (!tmpfile) { |
164 error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip); | 165 error = xfs_create(mnt_userns, XFS_I(dir), &name, mode, rdev, 166 &ip); |
165 } else { | 167 } else { |
166 error = xfs_create_tmpfile(XFS_I(dir), mode, &ip); | 168 error = xfs_create_tmpfile(mnt_userns, XFS_I(dir), mode, &ip); |
167 } 168 if (unlikely(error)) 169 goto out_free_acl; 170 171 inode = VFS_I(ip); 172 173 error = xfs_init_security(inode, dir, &dentry->d_name); 174 if (unlikely(error)) --- 46 unchanged lines hidden (view full) --- 221STATIC int 222xfs_vn_mknod( 223 struct user_namespace *mnt_userns, 224 struct inode *dir, 225 struct dentry *dentry, 226 umode_t mode, 227 dev_t rdev) 228{ | 169 } 170 if (unlikely(error)) 171 goto out_free_acl; 172 173 inode = VFS_I(ip); 174 175 error = xfs_init_security(inode, dir, &dentry->d_name); 176 if (unlikely(error)) --- 46 unchanged lines hidden (view full) --- 223STATIC int 224xfs_vn_mknod( 225 struct user_namespace *mnt_userns, 226 struct inode *dir, 227 struct dentry *dentry, 228 umode_t mode, 229 dev_t rdev) 230{ |
229 return xfs_generic_create(dir, dentry, mode, rdev, false); | 231 return xfs_generic_create(mnt_userns, dir, dentry, mode, rdev, false); |
230} 231 232STATIC int 233xfs_vn_create( 234 struct user_namespace *mnt_userns, 235 struct inode *dir, 236 struct dentry *dentry, 237 umode_t mode, 238 bool flags) 239{ | 232} 233 234STATIC int 235xfs_vn_create( 236 struct user_namespace *mnt_userns, 237 struct inode *dir, 238 struct dentry *dentry, 239 umode_t mode, 240 bool flags) 241{ |
240 return xfs_generic_create(dir, dentry, mode, 0, false); | 242 return xfs_generic_create(mnt_userns, dir, dentry, mode, 0, false); |
241} 242 243STATIC int 244xfs_vn_mkdir( 245 struct user_namespace *mnt_userns, 246 struct inode *dir, 247 struct dentry *dentry, 248 umode_t mode) 249{ | 243} 244 245STATIC int 246xfs_vn_mkdir( 247 struct user_namespace *mnt_userns, 248 struct inode *dir, 249 struct dentry *dentry, 250 umode_t mode) 251{ |
250 return xfs_generic_create(dir, dentry, mode | S_IFDIR, 0, false); | 252 return xfs_generic_create(mnt_userns, dir, dentry, mode | S_IFDIR, 0, 253 false); |
251} 252 253STATIC struct dentry * 254xfs_vn_lookup( 255 struct inode *dir, 256 struct dentry *dentry, 257 unsigned int flags) 258{ --- 117 unchanged lines hidden (view full) --- 376 umode_t mode; 377 378 mode = S_IFLNK | 379 (irix_symlink_mode ? 0777 & ~current_umask() : S_IRWXUGO); 380 error = xfs_dentry_mode_to_name(&name, dentry, mode); 381 if (unlikely(error)) 382 goto out; 383 | 254} 255 256STATIC struct dentry * 257xfs_vn_lookup( 258 struct inode *dir, 259 struct dentry *dentry, 260 unsigned int flags) 261{ --- 117 unchanged lines hidden (view full) --- 379 umode_t mode; 380 381 mode = S_IFLNK | 382 (irix_symlink_mode ? 0777 & ~current_umask() : S_IRWXUGO); 383 error = xfs_dentry_mode_to_name(&name, dentry, mode); 384 if (unlikely(error)) 385 goto out; 386 |
384 error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip); | 387 error = xfs_symlink(mnt_userns, XFS_I(dir), &name, symname, mode, &cip); |
385 if (unlikely(error)) 386 goto out; 387 388 inode = VFS_I(cip); 389 390 error = xfs_init_security(inode, dir, &dentry->d_name); 391 if (unlikely(error)) 392 goto out_cleanup_inode; --- 38 unchanged lines hidden (view full) --- 431 if (omode && unlikely(error)) 432 return error; 433 434 error = xfs_dentry_mode_to_name(&nname, ndentry, 435 d_inode(odentry)->i_mode); 436 if (unlikely(error)) 437 return error; 438 | 388 if (unlikely(error)) 389 goto out; 390 391 inode = VFS_I(cip); 392 393 error = xfs_init_security(inode, dir, &dentry->d_name); 394 if (unlikely(error)) 395 goto out_cleanup_inode; --- 38 unchanged lines hidden (view full) --- 434 if (omode && unlikely(error)) 435 return error; 436 437 error = xfs_dentry_mode_to_name(&nname, ndentry, 438 d_inode(odentry)->i_mode); 439 if (unlikely(error)) 440 return error; 441 |
439 return xfs_rename(XFS_I(odir), &oname, XFS_I(d_inode(odentry)), 440 XFS_I(ndir), &nname, | 442 return xfs_rename(mnt_userns, XFS_I(odir), &oname, 443 XFS_I(d_inode(odentry)), XFS_I(ndir), &nname, |
441 new_inode ? XFS_I(new_inode) : NULL, flags); 442} 443 444/* 445 * careful here - this function can get called recursively, so 446 * we need to be very careful about how much stack we use. 447 * uio is kmalloced for this reason... 448 */ --- 99 unchanged lines hidden (view full) --- 548 549 if (XFS_FORCED_SHUTDOWN(mp)) 550 return -EIO; 551 552 stat->size = XFS_ISIZE(ip); 553 stat->dev = inode->i_sb->s_dev; 554 stat->mode = inode->i_mode; 555 stat->nlink = inode->i_nlink; | 444 new_inode ? XFS_I(new_inode) : NULL, flags); 445} 446 447/* 448 * careful here - this function can get called recursively, so 449 * we need to be very careful about how much stack we use. 450 * uio is kmalloced for this reason... 451 */ --- 99 unchanged lines hidden (view full) --- 551 552 if (XFS_FORCED_SHUTDOWN(mp)) 553 return -EIO; 554 555 stat->size = XFS_ISIZE(ip); 556 stat->dev = inode->i_sb->s_dev; 557 stat->mode = inode->i_mode; 558 stat->nlink = inode->i_nlink; |
556 stat->uid = inode->i_uid; 557 stat->gid = inode->i_gid; | 559 stat->uid = i_uid_into_mnt(mnt_userns, inode); 560 stat->gid = i_gid_into_mnt(mnt_userns, inode); |
558 stat->ino = ip->i_ino; 559 stat->atime = inode->i_atime; 560 stat->mtime = inode->i_mtime; 561 stat->ctime = inode->i_ctime; 562 stat->blocks = 563 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks); 564 565 if (xfs_sb_version_has_v3inode(&mp->m_sb)) { --- 61 unchanged lines hidden (view full) --- 627 if (iattr->ia_valid & ATTR_CTIME) 628 inode->i_ctime = iattr->ia_ctime; 629 if (iattr->ia_valid & ATTR_MTIME) 630 inode->i_mtime = iattr->ia_mtime; 631} 632 633static int 634xfs_vn_change_ok( | 561 stat->ino = ip->i_ino; 562 stat->atime = inode->i_atime; 563 stat->mtime = inode->i_mtime; 564 stat->ctime = inode->i_ctime; 565 stat->blocks = 566 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks); 567 568 if (xfs_sb_version_has_v3inode(&mp->m_sb)) { --- 61 unchanged lines hidden (view full) --- 630 if (iattr->ia_valid & ATTR_CTIME) 631 inode->i_ctime = iattr->ia_ctime; 632 if (iattr->ia_valid & ATTR_MTIME) 633 inode->i_mtime = iattr->ia_mtime; 634} 635 636static int 637xfs_vn_change_ok( |
635 struct dentry *dentry, 636 struct iattr *iattr) | 638 struct user_namespace *mnt_userns, 639 struct dentry *dentry, 640 struct iattr *iattr) |
637{ 638 struct xfs_mount *mp = XFS_I(d_inode(dentry))->i_mount; 639 640 if (mp->m_flags & XFS_MOUNT_RDONLY) 641 return -EROFS; 642 643 if (XFS_FORCED_SHUTDOWN(mp)) 644 return -EIO; 645 | 641{ 642 struct xfs_mount *mp = XFS_I(d_inode(dentry))->i_mount; 643 644 if (mp->m_flags & XFS_MOUNT_RDONLY) 645 return -EROFS; 646 647 if (XFS_FORCED_SHUTDOWN(mp)) 648 return -EIO; 649 |
646 return setattr_prepare(&init_user_ns, dentry, iattr); | 650 return setattr_prepare(mnt_userns, dentry, iattr); |
647} 648 649/* 650 * Set non-size attributes of an inode. 651 * 652 * Caution: The caller of this function is responsible for calling 653 * setattr_prepare() or otherwise verifying the change is fine. 654 */ 655static int 656xfs_setattr_nonsize( | 651} 652 653/* 654 * Set non-size attributes of an inode. 655 * 656 * Caution: The caller of this function is responsible for calling 657 * setattr_prepare() or otherwise verifying the change is fine. 658 */ 659static int 660xfs_setattr_nonsize( |
661 struct user_namespace *mnt_userns, |
|
657 struct xfs_inode *ip, 658 struct iattr *iattr) 659{ 660 xfs_mount_t *mp = ip->i_mount; 661 struct inode *inode = VFS_I(ip); 662 int mask = iattr->ia_valid; 663 xfs_trans_t *tp; 664 int error; --- 143 unchanged lines hidden (view full) --- 808 /* 809 * XXX(hch): Updating the ACL entries is not atomic vs the i_mode 810 * update. We could avoid this with linked transactions 811 * and passing down the transaction pointer all the way 812 * to attr_set. No previous user of the generic 813 * Posix ACL code seems to care about this issue either. 814 */ 815 if (mask & ATTR_MODE) { | 662 struct xfs_inode *ip, 663 struct iattr *iattr) 664{ 665 xfs_mount_t *mp = ip->i_mount; 666 struct inode *inode = VFS_I(ip); 667 int mask = iattr->ia_valid; 668 xfs_trans_t *tp; 669 int error; --- 143 unchanged lines hidden (view full) --- 813 /* 814 * XXX(hch): Updating the ACL entries is not atomic vs the i_mode 815 * update. We could avoid this with linked transactions 816 * and passing down the transaction pointer all the way 817 * to attr_set. No previous user of the generic 818 * Posix ACL code seems to care about this issue either. 819 */ 820 if (mask & ATTR_MODE) { |
816 error = posix_acl_chmod(&init_user_ns, inode, inode->i_mode); | 821 error = posix_acl_chmod(mnt_userns, inode, inode->i_mode); |
817 if (error) 818 return error; 819 } 820 821 return 0; 822 823out_cancel: 824 xfs_trans_cancel(tp); --- 7 unchanged lines hidden (view full) --- 832/* 833 * Truncate file. Must have write permission and not be a directory. 834 * 835 * Caution: The caller of this function is responsible for calling 836 * setattr_prepare() or otherwise verifying the change is fine. 837 */ 838STATIC int 839xfs_setattr_size( | 822 if (error) 823 return error; 824 } 825 826 return 0; 827 828out_cancel: 829 xfs_trans_cancel(tp); --- 7 unchanged lines hidden (view full) --- 837/* 838 * Truncate file. Must have write permission and not be a directory. 839 * 840 * Caution: The caller of this function is responsible for calling 841 * setattr_prepare() or otherwise verifying the change is fine. 842 */ 843STATIC int 844xfs_setattr_size( |
845 struct user_namespace *mnt_userns, |
|
840 struct xfs_inode *ip, 841 struct iattr *iattr) 842{ 843 struct xfs_mount *mp = ip->i_mount; 844 struct inode *inode = VFS_I(ip); 845 xfs_off_t oldsize, newsize; 846 struct xfs_trans *tp; 847 int error; --- 15 unchanged lines hidden (view full) --- 863 if (newsize == 0 && oldsize == 0 && ip->i_df.if_nextents == 0) { 864 if (!(iattr->ia_valid & (ATTR_CTIME|ATTR_MTIME))) 865 return 0; 866 867 /* 868 * Use the regular setattr path to update the timestamps. 869 */ 870 iattr->ia_valid &= ~ATTR_SIZE; | 846 struct xfs_inode *ip, 847 struct iattr *iattr) 848{ 849 struct xfs_mount *mp = ip->i_mount; 850 struct inode *inode = VFS_I(ip); 851 xfs_off_t oldsize, newsize; 852 struct xfs_trans *tp; 853 int error; --- 15 unchanged lines hidden (view full) --- 869 if (newsize == 0 && oldsize == 0 && ip->i_df.if_nextents == 0) { 870 if (!(iattr->ia_valid & (ATTR_CTIME|ATTR_MTIME))) 871 return 0; 872 873 /* 874 * Use the regular setattr path to update the timestamps. 875 */ 876 iattr->ia_valid &= ~ATTR_SIZE; |
871 return xfs_setattr_nonsize(ip, iattr); | 877 return xfs_setattr_nonsize(mnt_userns, ip, iattr); |
872 } 873 874 /* 875 * Make sure that the dquots are attached to the inode. 876 */ 877 error = xfs_qm_dqattach(ip); 878 if (error) 879 return error; --- 152 unchanged lines hidden (view full) --- 1032 1033out_trans_cancel: 1034 xfs_trans_cancel(tp); 1035 goto out_unlock; 1036} 1037 1038int 1039xfs_vn_setattr_size( | 878 } 879 880 /* 881 * Make sure that the dquots are attached to the inode. 882 */ 883 error = xfs_qm_dqattach(ip); 884 if (error) 885 return error; --- 152 unchanged lines hidden (view full) --- 1038 1039out_trans_cancel: 1040 xfs_trans_cancel(tp); 1041 goto out_unlock; 1042} 1043 1044int 1045xfs_vn_setattr_size( |
1046 struct user_namespace *mnt_userns, |
|
1040 struct dentry *dentry, 1041 struct iattr *iattr) 1042{ 1043 struct xfs_inode *ip = XFS_I(d_inode(dentry)); 1044 int error; 1045 1046 trace_xfs_setattr(ip); 1047 | 1047 struct dentry *dentry, 1048 struct iattr *iattr) 1049{ 1050 struct xfs_inode *ip = XFS_I(d_inode(dentry)); 1051 int error; 1052 1053 trace_xfs_setattr(ip); 1054 |
1048 error = xfs_vn_change_ok(dentry, iattr); | 1055 error = xfs_vn_change_ok(mnt_userns, dentry, iattr); |
1049 if (error) 1050 return error; | 1056 if (error) 1057 return error; |
1051 return xfs_setattr_size(ip, iattr); | 1058 return xfs_setattr_size(mnt_userns, ip, iattr); |
1052} 1053 1054STATIC int 1055xfs_vn_setattr( 1056 struct user_namespace *mnt_userns, 1057 struct dentry *dentry, 1058 struct iattr *iattr) 1059{ --- 8 unchanged lines hidden (view full) --- 1068 iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL; 1069 1070 error = xfs_break_layouts(inode, &iolock, BREAK_UNMAP); 1071 if (error) { 1072 xfs_iunlock(ip, XFS_MMAPLOCK_EXCL); 1073 return error; 1074 } 1075 | 1059} 1060 1061STATIC int 1062xfs_vn_setattr( 1063 struct user_namespace *mnt_userns, 1064 struct dentry *dentry, 1065 struct iattr *iattr) 1066{ --- 8 unchanged lines hidden (view full) --- 1075 iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL; 1076 1077 error = xfs_break_layouts(inode, &iolock, BREAK_UNMAP); 1078 if (error) { 1079 xfs_iunlock(ip, XFS_MMAPLOCK_EXCL); 1080 return error; 1081 } 1082 |
1076 error = xfs_vn_setattr_size(dentry, iattr); | 1083 error = xfs_vn_setattr_size(mnt_userns, dentry, iattr); |
1077 xfs_iunlock(ip, XFS_MMAPLOCK_EXCL); 1078 } else { 1079 trace_xfs_setattr(ip); 1080 | 1084 xfs_iunlock(ip, XFS_MMAPLOCK_EXCL); 1085 } else { 1086 trace_xfs_setattr(ip); 1087 |
1081 error = xfs_vn_change_ok(dentry, iattr); | 1088 error = xfs_vn_change_ok(mnt_userns, dentry, iattr); |
1082 if (!error) | 1089 if (!error) |
1083 error = xfs_setattr_nonsize(ip, iattr); | 1090 error = xfs_setattr_nonsize(mnt_userns, ip, iattr); |
1084 } 1085 1086 return error; 1087} 1088 1089STATIC int 1090xfs_vn_update_time( 1091 struct inode *inode, --- 59 unchanged lines hidden (view full) --- 1151 1152STATIC int 1153xfs_vn_tmpfile( 1154 struct user_namespace *mnt_userns, 1155 struct inode *dir, 1156 struct dentry *dentry, 1157 umode_t mode) 1158{ | 1091 } 1092 1093 return error; 1094} 1095 1096STATIC int 1097xfs_vn_update_time( 1098 struct inode *inode, --- 59 unchanged lines hidden (view full) --- 1158 1159STATIC int 1160xfs_vn_tmpfile( 1161 struct user_namespace *mnt_userns, 1162 struct inode *dir, 1163 struct dentry *dentry, 1164 umode_t mode) 1165{ |
1159 return xfs_generic_create(dir, dentry, mode, 0, true); | 1166 return xfs_generic_create(mnt_userns, dir, dentry, mode, 0, true); |
1160} 1161 1162static const struct inode_operations xfs_inode_operations = { 1163 .get_acl = xfs_get_acl, 1164 .set_acl = xfs_set_acl, 1165 .getattr = xfs_vn_getattr, 1166 .setattr = xfs_vn_setattr, 1167 .listxattr = xfs_vn_listxattr, --- 231 unchanged lines hidden --- | 1167} 1168 1169static const struct inode_operations xfs_inode_operations = { 1170 .get_acl = xfs_get_acl, 1171 .set_acl = xfs_set_acl, 1172 .getattr = xfs_vn_getattr, 1173 .setattr = xfs_vn_setattr, 1174 .listxattr = xfs_vn_listxattr, --- 231 unchanged lines hidden --- |