hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/fs/xfs/xfs_pnfs.c
....@@ -2,22 +2,16 @@
22 /*
33 * Copyright (c) 2014 Christoph Hellwig.
44 */
5
-#include <linux/iomap.h>
65 #include "xfs.h"
6
+#include "xfs_shared.h"
77 #include "xfs_format.h"
88 #include "xfs_log_format.h"
99 #include "xfs_trans_resv.h"
10
-#include "xfs_sb.h"
1110 #include "xfs_mount.h"
1211 #include "xfs_inode.h"
1312 #include "xfs_trans.h"
14
-#include "xfs_log.h"
1513 #include "xfs_bmap.h"
16
-#include "xfs_bmap_util.h"
17
-#include "xfs_error.h"
1814 #include "xfs_iomap.h"
19
-#include "xfs_shared.h"
20
-#include "xfs_bit.h"
2115 #include "xfs_pnfs.h"
2216
2317 /*
....@@ -39,7 +33,7 @@
3933 struct xfs_inode *ip = XFS_I(inode);
4034 int error;
4135
42
- while ((error = break_layout(inode, false) == -EWOULDBLOCK)) {
36
+ while ((error = break_layout(inode, false)) == -EWOULDBLOCK) {
4337 xfs_iunlock(ip, *iolock);
4438 *did_unlock = true;
4539 error = break_layout(inode, true);
....@@ -64,9 +58,8 @@
6458 {
6559 struct xfs_mount *mp = XFS_M(sb);
6660
67
- printk_once(KERN_NOTICE
68
-"XFS (%s): using experimental pNFS feature, use at your own risk!\n",
69
- mp->m_fsname);
61
+ xfs_notice_once(mp,
62
+"Using experimental pNFS feature, use at your own risk!");
7063
7164 if (*len < sizeof(uuid_t))
7265 return -EINVAL;
....@@ -149,43 +142,40 @@
149142 lock_flags = xfs_ilock_data_map_shared(ip);
150143 error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb,
151144 &imap, &nimaps, bmapi_flags);
152
- xfs_iunlock(ip, lock_flags);
153145
154
- if (error)
155
- goto out_unlock;
146
+ ASSERT(!nimaps || imap.br_startblock != DELAYSTARTBLOCK);
156147
157
- if (write) {
158
- enum xfs_prealloc_flags flags = 0;
148
+ if (!error && write &&
149
+ (!nimaps || imap.br_startblock == HOLESTARTBLOCK)) {
150
+ if (offset + length > XFS_ISIZE(ip))
151
+ end_fsb = xfs_iomap_eof_align_last_fsb(ip, end_fsb);
152
+ else if (nimaps && imap.br_startblock == HOLESTARTBLOCK)
153
+ end_fsb = min(end_fsb, imap.br_startoff +
154
+ imap.br_blockcount);
155
+ xfs_iunlock(ip, lock_flags);
159156
160
- ASSERT(imap.br_startblock != DELAYSTARTBLOCK);
161
-
162
- if (!nimaps || imap.br_startblock == HOLESTARTBLOCK) {
163
- /*
164
- * xfs_iomap_write_direct() expects to take ownership of
165
- * the shared ilock.
166
- */
167
- xfs_ilock(ip, XFS_ILOCK_SHARED);
168
- error = xfs_iomap_write_direct(ip, offset, length,
169
- &imap, nimaps);
170
- if (error)
171
- goto out_unlock;
172
-
173
- /*
174
- * Ensure the next transaction is committed
175
- * synchronously so that the blocks allocated and
176
- * handed out to the client are guaranteed to be
177
- * present even after a server crash.
178
- */
179
- flags |= XFS_PREALLOC_SET | XFS_PREALLOC_SYNC;
180
- }
181
-
182
- error = xfs_update_prealloc_flags(ip, flags);
157
+ error = xfs_iomap_write_direct(ip, offset_fsb,
158
+ end_fsb - offset_fsb, &imap);
183159 if (error)
184160 goto out_unlock;
161
+
162
+ /*
163
+ * Ensure the next transaction is committed synchronously so
164
+ * that the blocks allocated and handed out to the client are
165
+ * guaranteed to be present even after a server crash.
166
+ */
167
+ error = xfs_update_prealloc_flags(ip, XFS_PREALLOC_SET);
168
+ if (!error)
169
+ error = xfs_log_force_inode(ip);
170
+ if (error)
171
+ goto out_unlock;
172
+
173
+ } else {
174
+ xfs_iunlock(ip, lock_flags);
185175 }
186176 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
187177
188
- xfs_bmbt_to_iomap(ip, iomap, &imap);
178
+ error = xfs_bmbt_to_iomap(ip, iomap, &imap, 0);
189179 *device_generation = mp->m_generation;
190180 return error;
191181 out_unlock:
....@@ -295,7 +285,8 @@
295285 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
296286 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
297287
298
- xfs_setattr_time(ip, iattr);
288
+ ASSERT(!(iattr->ia_valid & (ATTR_UID | ATTR_GID)));
289
+ setattr_copy(inode, iattr);
299290 if (update_isize) {
300291 i_size_write(inode, iattr->ia_size);
301292 ip->i_d.di_size = iattr->ia_size;