forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/fs/xfs/xfs_iops.c
....@@ -10,38 +10,29 @@
1010 #include "xfs_log_format.h"
1111 #include "xfs_trans_resv.h"
1212 #include "xfs_mount.h"
13
-#include "xfs_da_format.h"
1413 #include "xfs_inode.h"
15
-#include "xfs_bmap.h"
16
-#include "xfs_bmap_util.h"
1714 #include "xfs_acl.h"
1815 #include "xfs_quota.h"
19
-#include "xfs_error.h"
2016 #include "xfs_attr.h"
2117 #include "xfs_trans.h"
2218 #include "xfs_trace.h"
2319 #include "xfs_icache.h"
2420 #include "xfs_symlink.h"
25
-#include "xfs_da_btree.h"
2621 #include "xfs_dir2.h"
27
-#include "xfs_trans_space.h"
2822 #include "xfs_iomap.h"
29
-#include "xfs_defer.h"
23
+#include "xfs_error.h"
3024
31
-#include <linux/capability.h>
32
-#include <linux/xattr.h>
3325 #include <linux/posix_acl.h>
3426 #include <linux/security.h>
35
-#include <linux/iomap.h>
36
-#include <linux/slab.h>
3727 #include <linux/iversion.h>
28
+#include <linux/fiemap.h>
3829
3930 /*
40
- * Directories have different lock order w.r.t. mmap_sem compared to regular
31
+ * Directories have different lock order w.r.t. mmap_lock compared to regular
4132 * files. This is due to readdir potentially triggering page faults on a user
4233 * buffer inside filldir(), and this happens with the ilock on the directory
4334 * held. For regular files, the lock order is the other way around - the
44
- * mmap_sem is taken during the page fault, and then we lock the ilock to do
35
+ * mmap_lock is taken during the page fault, and then we lock the ilock to do
4536 * block mapping. Hence we need a different class for the directory ilock so
4637 * that lockdep can tell them apart.
4738 */
....@@ -59,8 +50,15 @@
5950 int error = 0;
6051
6152 for (xattr = xattr_array; xattr->name != NULL; xattr++) {
62
- error = xfs_attr_set(ip, xattr->name, xattr->value,
63
- xattr->value_len, ATTR_SECURE);
53
+ struct xfs_da_args args = {
54
+ .dp = ip,
55
+ .attr_filter = XFS_ATTR_SECURE,
56
+ .name = xattr->name,
57
+ .namelen = strlen(xattr->name),
58
+ .value = xattr->value,
59
+ .valuelen = xattr->value_len,
60
+ };
61
+ error = xfs_attr_set(&args);
6462 if (error < 0)
6563 break;
6664 }
....@@ -239,7 +237,7 @@
239237 umode_t mode,
240238 bool flags)
241239 {
242
- return xfs_vn_mknod(dir, dentry, mode, 0);
240
+ return xfs_generic_create(dir, dentry, mode, 0, false);
243241 }
244242
245243 STATIC int
....@@ -248,7 +246,7 @@
248246 struct dentry *dentry,
249247 umode_t mode)
250248 {
251
- return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
249
+ return xfs_generic_create(dir, dentry, mode | S_IFDIR, 0, false);
252250 }
253251
254252 STATIC struct dentry *
....@@ -480,18 +478,55 @@
480478 struct inode *inode,
481479 struct delayed_call *done)
482480 {
481
+ struct xfs_inode *ip = XFS_I(inode);
483482 char *link;
484483
485
- ASSERT(XFS_I(inode)->i_df.if_flags & XFS_IFINLINE);
484
+ ASSERT(ip->i_df.if_flags & XFS_IFINLINE);
486485
487486 /*
488487 * The VFS crashes on a NULL pointer, so return -EFSCORRUPTED if
489488 * if_data is junk.
490489 */
491
- link = XFS_I(inode)->i_df.if_u1.if_data;
492
- if (!link)
490
+ link = ip->i_df.if_u1.if_data;
491
+ if (XFS_IS_CORRUPT(ip->i_mount, !link))
493492 return ERR_PTR(-EFSCORRUPTED);
494493 return link;
494
+}
495
+
496
+static uint32_t
497
+xfs_stat_blksize(
498
+ struct xfs_inode *ip)
499
+{
500
+ struct xfs_mount *mp = ip->i_mount;
501
+
502
+ /*
503
+ * If the file blocks are being allocated from a realtime volume, then
504
+ * always return the realtime extent size.
505
+ */
506
+ if (XFS_IS_REALTIME_INODE(ip))
507
+ return xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
508
+
509
+ /*
510
+ * Allow large block sizes to be reported to userspace programs if the
511
+ * "largeio" mount option is used.
512
+ *
513
+ * If compatibility mode is specified, simply return the basic unit of
514
+ * caching so that we don't get inefficient read/modify/write I/O from
515
+ * user apps. Otherwise....
516
+ *
517
+ * If the underlying volume is a stripe, then return the stripe width in
518
+ * bytes as the recommended I/O size. It is not a stripe and we've set a
519
+ * default buffered I/O size, return that, otherwise return the compat
520
+ * default.
521
+ */
522
+ if (mp->m_flags & XFS_MOUNT_LARGEIO) {
523
+ if (mp->m_swidth)
524
+ return mp->m_swidth << mp->m_sb.sb_blocklog;
525
+ if (mp->m_flags & XFS_MOUNT_ALLOCSIZE)
526
+ return 1U << mp->m_allocsize_log;
527
+ }
528
+
529
+ return PAGE_SIZE;
495530 }
496531
497532 STATIC int
....@@ -523,11 +558,10 @@
523558 stat->blocks =
524559 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
525560
526
- if (ip->i_d.di_version == 3) {
561
+ if (xfs_sb_version_has_v3inode(&mp->m_sb)) {
527562 if (request_mask & STATX_BTIME) {
528563 stat->result_mask |= STATX_BTIME;
529
- stat->btime.tv_sec = ip->i_d.di_crtime.t_sec;
530
- stat->btime.tv_nsec = ip->i_d.di_crtime.t_nsec;
564
+ stat->btime = ip->i_d.di_crtime;
531565 }
532566 }
533567
....@@ -553,16 +587,7 @@
553587 stat->rdev = inode->i_rdev;
554588 break;
555589 default:
556
- if (XFS_IS_REALTIME_INODE(ip)) {
557
- /*
558
- * If the file blocks are being allocated from a
559
- * realtime volume, then return the inode's realtime
560
- * extent size or the realtime volume's extent size.
561
- */
562
- stat->blksize =
563
- xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
564
- } else
565
- stat->blksize = xfs_preferred_iosize(mp);
590
+ stat->blksize = xfs_stat_blksize(ip);
566591 stat->rdev = 0;
567592 break;
568593 }
....@@ -672,9 +697,7 @@
672697 */
673698 ASSERT(udqp == NULL);
674699 ASSERT(gdqp == NULL);
675
- error = xfs_qm_vop_dqalloc(ip, xfs_kuid_to_uid(uid),
676
- xfs_kgid_to_gid(gid),
677
- xfs_get_projid(ip),
700
+ error = xfs_qm_vop_dqalloc(ip, uid, gid, ip->i_d.di_projid,
678701 qflags, &udqp, &gdqp, NULL);
679702 if (error)
680703 return error;
....@@ -716,12 +739,7 @@
716739 if (error) /* out of quota */
717740 goto out_cancel;
718741 }
719
- }
720742
721
- /*
722
- * Change file ownership. Must be the owner or privileged.
723
- */
724
- if (mask & (ATTR_UID|ATTR_GID)) {
725743 /*
726744 * CAP_FSETID overrides the following restrictions:
727745 *
....@@ -743,7 +761,6 @@
743761 olddquot1 = xfs_qm_vop_chown(tp, ip,
744762 &ip->i_udquot, udqp);
745763 }
746
- ip->i_d.di_uid = xfs_kuid_to_uid(uid);
747764 inode->i_uid = uid;
748765 }
749766 if (!gid_eq(igid, gid)) {
....@@ -755,7 +772,6 @@
755772 olddquot2 = xfs_qm_vop_chown(tp, ip,
756773 &ip->i_gdquot, gdqp);
757774 }
758
- ip->i_d.di_gid = xfs_kgid_to_gid(gid);
759775 inode->i_gid = gid;
760776 }
761777 }
....@@ -857,7 +873,7 @@
857873 /*
858874 * Short circuit the truncate case for zero length files.
859875 */
860
- if (newsize == 0 && oldsize == 0 && ip->i_d.di_nextents == 0) {
876
+ if (newsize == 0 && oldsize == 0 && ip->i_df.if_nextents == 0) {
861877 if (!(iattr->ia_valid & (ATTR_CTIME|ATTR_MTIME)))
862878 return 0;
863879
....@@ -893,7 +909,7 @@
893909 if (newsize > oldsize) {
894910 trace_xfs_zero_eof(ip, oldsize, newsize - oldsize);
895911 error = iomap_zero_range(inode, oldsize, newsize - oldsize,
896
- &did_zeroing, &xfs_iomap_ops);
912
+ &did_zeroing, &xfs_buffered_write_iomap_ops);
897913 } else {
898914 /*
899915 * iomap won't detect a dirty page over an unwritten block (or a
....@@ -906,7 +922,7 @@
906922 if (error)
907923 return error;
908924 error = iomap_truncate_page(inode, newsize, &did_zeroing,
909
- &xfs_iomap_ops);
925
+ &xfs_buffered_write_iomap_ops);
910926 }
911927
912928 if (error)
....@@ -1134,7 +1150,7 @@
11341150 &xfs_xattr_iomap_ops);
11351151 } else {
11361152 error = iomap_fiemap(inode, fieinfo, start, length,
1137
- &xfs_iomap_ops);
1153
+ &xfs_read_iomap_ops);
11381154 }
11391155 xfs_iunlock(XFS_I(inode), XFS_IOLOCK_SHARED);
11401156
....@@ -1233,13 +1249,12 @@
12331249 {
12341250 struct xfs_mount *mp = ip->i_mount;
12351251
1236
- /* Only supported on non-reflinked files. */
1237
- if (!S_ISREG(VFS_I(ip)->i_mode) || xfs_is_reflink_inode(ip))
1252
+ /* Only supported on regular files. */
1253
+ if (!S_ISREG(VFS_I(ip)->i_mode))
12381254 return false;
12391255
1240
- /* DAX mount option or DAX iflag must be set. */
1241
- if (!(mp->m_flags & XFS_MOUNT_DAX) &&
1242
- !(ip->i_d.di_flags2 & XFS_DIFLAG2_DAX))
1256
+ /* Only supported on non-reflinked files. */
1257
+ if (xfs_is_reflink_inode(ip))
12431258 return false;
12441259
12451260 /* Block size must match page size */
....@@ -1247,29 +1262,54 @@
12471262 return false;
12481263
12491264 /* Device has to support DAX too. */
1250
- return xfs_find_daxdev_for_inode(VFS_I(ip)) != NULL;
1265
+ return xfs_inode_buftarg(ip)->bt_daxdev != NULL;
12511266 }
12521267
1253
-STATIC void
1254
-xfs_diflags_to_iflags(
1255
- struct inode *inode,
1256
- struct xfs_inode *ip)
1268
+static bool
1269
+xfs_inode_should_enable_dax(
1270
+ struct xfs_inode *ip)
12571271 {
1258
- uint16_t flags = ip->i_d.di_flags;
1272
+ if (!IS_ENABLED(CONFIG_FS_DAX))
1273
+ return false;
1274
+ if (ip->i_mount->m_flags & XFS_MOUNT_DAX_NEVER)
1275
+ return false;
1276
+ if (!xfs_inode_supports_dax(ip))
1277
+ return false;
1278
+ if (ip->i_mount->m_flags & XFS_MOUNT_DAX_ALWAYS)
1279
+ return true;
1280
+ if (ip->i_d.di_flags2 & XFS_DIFLAG2_DAX)
1281
+ return true;
1282
+ return false;
1283
+}
12591284
1260
- inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC |
1261
- S_NOATIME | S_DAX);
1285
+void
1286
+xfs_diflags_to_iflags(
1287
+ struct xfs_inode *ip,
1288
+ bool init)
1289
+{
1290
+ struct inode *inode = VFS_I(ip);
1291
+ unsigned int xflags = xfs_ip2xflags(ip);
1292
+ unsigned int flags = 0;
12621293
1263
- if (flags & XFS_DIFLAG_IMMUTABLE)
1264
- inode->i_flags |= S_IMMUTABLE;
1265
- if (flags & XFS_DIFLAG_APPEND)
1266
- inode->i_flags |= S_APPEND;
1267
- if (flags & XFS_DIFLAG_SYNC)
1268
- inode->i_flags |= S_SYNC;
1269
- if (flags & XFS_DIFLAG_NOATIME)
1270
- inode->i_flags |= S_NOATIME;
1271
- if (xfs_inode_supports_dax(ip))
1272
- inode->i_flags |= S_DAX;
1294
+ ASSERT(!(IS_DAX(inode) && init));
1295
+
1296
+ if (xflags & FS_XFLAG_IMMUTABLE)
1297
+ flags |= S_IMMUTABLE;
1298
+ if (xflags & FS_XFLAG_APPEND)
1299
+ flags |= S_APPEND;
1300
+ if (xflags & FS_XFLAG_SYNC)
1301
+ flags |= S_SYNC;
1302
+ if (xflags & FS_XFLAG_NOATIME)
1303
+ flags |= S_NOATIME;
1304
+ if (init && xfs_inode_should_enable_dax(ip))
1305
+ flags |= S_DAX;
1306
+
1307
+ /*
1308
+ * S_DAX can only be set during inode initialization and is never set by
1309
+ * the VFS, so we cannot mask off S_DAX in i_flags.
1310
+ */
1311
+ inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME);
1312
+ inode->i_flags |= flags;
12731313 }
12741314
12751315 /*
....@@ -1288,17 +1328,14 @@
12881328 gfp_t gfp_mask;
12891329
12901330 inode->i_ino = ip->i_ino;
1291
- inode->i_state = I_NEW;
1331
+ inode->i_state |= I_NEW;
12921332
12931333 inode_sb_list_add(inode);
12941334 /* make the inode look hashed for the writeback code */
12951335 inode_fake_hash(inode);
12961336
1297
- inode->i_uid = xfs_uid_to_kuid(ip->i_d.di_uid);
1298
- inode->i_gid = xfs_gid_to_kgid(ip->i_d.di_gid);
1299
-
13001337 i_size_write(inode, ip->i_d.di_size);
1301
- xfs_diflags_to_iflags(inode, ip);
1338
+ xfs_diflags_to_iflags(ip, true);
13021339
13031340 if (S_ISDIR(inode->i_mode)) {
13041341 /*
....@@ -1310,9 +1347,7 @@
13101347 lockdep_set_class(&inode->i_rwsem,
13111348 &inode->i_sb->s_type->i_mutex_dir_key);
13121349 lockdep_set_class(&ip->i_lock.mr_lock, &xfs_dir_ilock_class);
1313
- ip->d_ops = ip->i_mount->m_dir_inode_ops;
13141350 } else {
1315
- ip->d_ops = ip->i_mount->m_nondir_inode_ops;
13161351 lockdep_set_class(&ip->i_lock.mr_lock, &xfs_nondir_ilock_class);
13171352 }
13181353