blob: 110c038910ff39580cabb45cf52f4f504c0b4332 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include "xfs_fs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110020#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110022#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "xfs_trans.h"
24#include "xfs_sb.h"
25#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_dir2.h"
27#include "xfs_alloc.h"
28#include "xfs_dmapi.h"
29#include "xfs_quota.h"
30#include "xfs_mount.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "xfs_bmap_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110032#include "xfs_alloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "xfs_ialloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_dir2_sf.h"
Nathan Scotta844f452005-11-02 14:38:42 +110035#include "xfs_attr_sf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "xfs_dinode.h"
37#include "xfs_inode.h"
38#include "xfs_bmap.h"
Nathan Scotta844f452005-11-02 14:38:42 +110039#include "xfs_btree.h"
40#include "xfs_ialloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "xfs_rtalloc.h"
42#include "xfs_error.h"
43#include "xfs_itable.h"
44#include "xfs_rw.h"
45#include "xfs_acl.h"
46#include "xfs_cap.h"
47#include "xfs_mac.h"
48#include "xfs_attr.h"
49#include "xfs_inode_item.h"
50#include "xfs_buf_item.h"
51#include "xfs_utils.h"
52#include "xfs_iomap.h"
53
54#include <linux/capability.h>
55#include <linux/writeback.h>
56
57
58#if defined(XFS_RW_TRACE)
59void
60xfs_rw_enter_trace(
61 int tag,
62 xfs_iocore_t *io,
63 void *data,
64 size_t segs,
65 loff_t offset,
66 int ioflags)
67{
68 xfs_inode_t *ip = XFS_IO_INODE(io);
69
70 if (ip->i_rwtrace == NULL)
71 return;
72 ktrace_enter(ip->i_rwtrace,
73 (void *)(unsigned long)tag,
74 (void *)ip,
75 (void *)((unsigned long)((ip->i_d.di_size >> 32) & 0xffffffff)),
76 (void *)((unsigned long)(ip->i_d.di_size & 0xffffffff)),
77 (void *)data,
78 (void *)((unsigned long)segs),
79 (void *)((unsigned long)((offset >> 32) & 0xffffffff)),
80 (void *)((unsigned long)(offset & 0xffffffff)),
81 (void *)((unsigned long)ioflags),
82 (void *)((unsigned long)((io->io_new_size >> 32) & 0xffffffff)),
83 (void *)((unsigned long)(io->io_new_size & 0xffffffff)),
Yingping Luf1fdc842006-03-22 12:44:15 +110084 (void *)((unsigned long)current_pid()),
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 (void *)NULL,
86 (void *)NULL,
87 (void *)NULL,
88 (void *)NULL);
89}
90
91void
92xfs_inval_cached_trace(
93 xfs_iocore_t *io,
94 xfs_off_t offset,
95 xfs_off_t len,
96 xfs_off_t first,
97 xfs_off_t last)
98{
99 xfs_inode_t *ip = XFS_IO_INODE(io);
100
101 if (ip->i_rwtrace == NULL)
102 return;
103 ktrace_enter(ip->i_rwtrace,
104 (void *)(__psint_t)XFS_INVAL_CACHED,
105 (void *)ip,
106 (void *)((unsigned long)((offset >> 32) & 0xffffffff)),
107 (void *)((unsigned long)(offset & 0xffffffff)),
108 (void *)((unsigned long)((len >> 32) & 0xffffffff)),
109 (void *)((unsigned long)(len & 0xffffffff)),
110 (void *)((unsigned long)((first >> 32) & 0xffffffff)),
111 (void *)((unsigned long)(first & 0xffffffff)),
112 (void *)((unsigned long)((last >> 32) & 0xffffffff)),
113 (void *)((unsigned long)(last & 0xffffffff)),
Yingping Luf1fdc842006-03-22 12:44:15 +1100114 (void *)((unsigned long)current_pid()),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 (void *)NULL,
116 (void *)NULL,
117 (void *)NULL,
118 (void *)NULL,
119 (void *)NULL);
120}
121#endif
122
123/*
124 * xfs_iozero
125 *
126 * xfs_iozero clears the specified range of buffer supplied,
127 * and marks all the affected blocks as valid and modified. If
128 * an affected block is not allocated, it will be allocated. If
129 * an affected block is not completely overwritten, and is not
130 * valid before the operation, it will be read from disk before
131 * being partially zeroed.
132 */
133STATIC int
134xfs_iozero(
135 struct inode *ip, /* inode */
136 loff_t pos, /* offset in file */
137 size_t count, /* size of data to zero */
138 loff_t end_size) /* max file size to set */
139{
140 unsigned bytes;
141 struct page *page;
142 struct address_space *mapping;
143 char *kaddr;
144 int status;
145
146 mapping = ip->i_mapping;
147 do {
148 unsigned long index, offset;
149
150 offset = (pos & (PAGE_CACHE_SIZE -1)); /* Within page */
151 index = pos >> PAGE_CACHE_SHIFT;
152 bytes = PAGE_CACHE_SIZE - offset;
153 if (bytes > count)
154 bytes = count;
155
156 status = -ENOMEM;
157 page = grab_cache_page(mapping, index);
158 if (!page)
159 break;
160
161 kaddr = kmap(page);
162 status = mapping->a_ops->prepare_write(NULL, page, offset,
163 offset + bytes);
164 if (status) {
165 goto unlock;
166 }
167
168 memset((void *) (kaddr + offset), 0, bytes);
169 flush_dcache_page(page);
170 status = mapping->a_ops->commit_write(NULL, page, offset,
171 offset + bytes);
172 if (!status) {
173 pos += bytes;
174 count -= bytes;
175 if (pos > i_size_read(ip))
176 i_size_write(ip, pos < end_size ? pos : end_size);
177 }
178
179unlock:
180 kunmap(page);
181 unlock_page(page);
182 page_cache_release(page);
183 if (status)
184 break;
185 } while (count);
186
187 return (-status);
188}
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190ssize_t /* bytes read, or (-) error */
191xfs_read(
192 bhv_desc_t *bdp,
193 struct kiocb *iocb,
194 const struct iovec *iovp,
195 unsigned int segs,
196 loff_t *offset,
197 int ioflags,
198 cred_t *credp)
199{
200 struct file *file = iocb->ki_filp;
201 struct inode *inode = file->f_mapping->host;
202 size_t size = 0;
203 ssize_t ret;
204 xfs_fsize_t n;
205 xfs_inode_t *ip;
206 xfs_mount_t *mp;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000207 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 unsigned long seg;
209
210 ip = XFS_BHVTOI(bdp);
211 vp = BHV_TO_VNODE(bdp);
212 mp = ip->i_mount;
213
214 XFS_STATS_INC(xs_read_calls);
215
216 /* START copy & waste from filemap.c */
217 for (seg = 0; seg < segs; seg++) {
218 const struct iovec *iv = &iovp[seg];
219
220 /*
221 * If any segment has a negative length, or the cumulative
222 * length ever wraps negative then return -EINVAL.
223 */
224 size += iv->iov_len;
225 if (unlikely((ssize_t)(size|iv->iov_len) < 0))
226 return XFS_ERROR(-EINVAL);
227 }
228 /* END copy & waste from filemap.c */
229
230 if (unlikely(ioflags & IO_ISDIRECT)) {
231 xfs_buftarg_t *target =
232 (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
233 mp->m_rtdev_targp : mp->m_ddev_targp;
Nathan Scottce8e9222006-01-11 15:39:08 +1100234 if ((*offset & target->bt_smask) ||
235 (size & target->bt_smask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 if (*offset == ip->i_d.di_size) {
237 return (0);
238 }
239 return -XFS_ERROR(EINVAL);
240 }
241 }
242
243 n = XFS_MAXIOFFSET(mp) - *offset;
244 if ((n <= 0) || (size == 0))
245 return 0;
246
247 if (n < size)
248 size = n;
249
Nathan Scotta13828b2006-03-17 17:26:14 +1100250 if (XFS_FORCED_SHUTDOWN(mp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 if (unlikely(ioflags & IO_ISDIRECT))
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800254 mutex_lock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 xfs_ilock(ip, XFS_IOLOCK_SHARED);
256
257 if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ) &&
258 !(ioflags & IO_INVIS)) {
Nathan Scott8285fb52006-06-09 17:07:12 +1000259 bhv_vrwlock_t locktype = VRWLOCK_READ;
Dean Roehriche1a40fa2005-06-22 10:20:44 +1000260 int dmflags = FILP_DELAY_FLAG(file) | DM_SEM_FLAG_RD(ioflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 ret = -XFS_SEND_DATA(mp, DM_EVENT_READ,
263 BHV_TO_VNODE(bdp), *offset, size,
Dean Roehriche1a40fa2005-06-22 10:20:44 +1000264 dmflags, &locktype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if (ret) {
266 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
Lachlan McIlroy721259b2006-09-07 14:27:05 +1000267 if (unlikely(ioflags & IO_ISDIRECT))
268 mutex_unlock(&inode->i_mutex);
269 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
271 }
272
Nathan Scott9cea2362006-03-17 17:26:41 +1100273 if (unlikely((ioflags & IO_ISDIRECT) && VN_CACHED(vp)))
Nathan Scott67fcaa72006-06-09 17:00:52 +1000274 bhv_vop_flushinval_pages(vp, ctooff(offtoct(*offset)),
Nathan Scott9cea2362006-03-17 17:26:41 +1100275 -1, FI_REMAPF_LOCKED);
276
Lachlan McIlroy721259b2006-09-07 14:27:05 +1000277 if (unlikely(ioflags & IO_ISDIRECT))
278 mutex_unlock(&inode->i_mutex);
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 xfs_rw_enter_trace(XFS_READ_ENTER, &ip->i_iocore,
281 (void *)iovp, segs, *offset, ioflags);
282 ret = __generic_file_aio_read(iocb, iovp, segs, offset);
283 if (ret == -EIOCBQUEUED && !(ioflags & IO_ISAIO))
284 ret = wait_on_sync_kiocb(iocb);
285 if (ret > 0)
286 XFS_STATS_ADD(xs_read_bytes, ret);
287
288 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 return ret;
290}
291
292ssize_t
293xfs_sendfile(
294 bhv_desc_t *bdp,
295 struct file *filp,
296 loff_t *offset,
297 int ioflags,
298 size_t count,
299 read_actor_t actor,
300 void *target,
301 cred_t *credp)
302{
Nathan Scott1b895842006-03-31 13:08:59 +1000303 xfs_inode_t *ip = XFS_BHVTOI(bdp);
304 xfs_mount_t *mp = ip->i_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 XFS_STATS_INC(xs_read_calls);
Nathan Scott1b895842006-03-31 13:08:59 +1000308 if (XFS_FORCED_SHUTDOWN(mp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 return -EIO;
310
311 xfs_ilock(ip, XFS_IOLOCK_SHARED);
312
Nathan Scott1b895842006-03-31 13:08:59 +1000313 if (DM_EVENT_ENABLED(BHV_TO_VNODE(bdp)->v_vfsp, ip, DM_EVENT_READ) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 (!(ioflags & IO_INVIS))) {
Nathan Scott8285fb52006-06-09 17:07:12 +1000315 bhv_vrwlock_t locktype = VRWLOCK_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 int error;
317
Nathan Scott1b895842006-03-31 13:08:59 +1000318 error = XFS_SEND_DATA(mp, DM_EVENT_READ, BHV_TO_VNODE(bdp),
319 *offset, count,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 FILP_DELAY_FLAG(filp), &locktype);
321 if (error) {
322 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
323 return -error;
324 }
325 }
326 xfs_rw_enter_trace(XFS_SENDFILE_ENTER, &ip->i_iocore,
327 (void *)(unsigned long)target, count, *offset, ioflags);
328 ret = generic_file_sendfile(filp, offset, count, actor, target);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 if (ret > 0)
330 XFS_STATS_ADD(xs_read_bytes, ret);
331
Nathan Scott1b895842006-03-31 13:08:59 +1000332 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
333 return ret;
334}
335
336ssize_t
337xfs_splice_read(
338 bhv_desc_t *bdp,
339 struct file *infilp,
Jens Axboecbb7e572006-04-11 14:57:50 +0200340 loff_t *ppos,
Ingo Molnar3a326a22006-04-10 15:18:35 +0200341 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000342 size_t count,
343 int flags,
344 int ioflags,
345 cred_t *credp)
346{
347 xfs_inode_t *ip = XFS_BHVTOI(bdp);
348 xfs_mount_t *mp = ip->i_mount;
349 ssize_t ret;
350
351 XFS_STATS_INC(xs_read_calls);
352 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
353 return -EIO;
354
355 xfs_ilock(ip, XFS_IOLOCK_SHARED);
356
357 if (DM_EVENT_ENABLED(BHV_TO_VNODE(bdp)->v_vfsp, ip, DM_EVENT_READ) &&
358 (!(ioflags & IO_INVIS))) {
Nathan Scott8285fb52006-06-09 17:07:12 +1000359 bhv_vrwlock_t locktype = VRWLOCK_READ;
Nathan Scott1b895842006-03-31 13:08:59 +1000360 int error;
361
362 error = XFS_SEND_DATA(mp, DM_EVENT_READ, BHV_TO_VNODE(bdp),
Jens Axboecbb7e572006-04-11 14:57:50 +0200363 *ppos, count,
Nathan Scott1b895842006-03-31 13:08:59 +1000364 FILP_DELAY_FLAG(infilp), &locktype);
365 if (error) {
366 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
367 return -error;
368 }
369 }
370 xfs_rw_enter_trace(XFS_SPLICE_READ_ENTER, &ip->i_iocore,
Jens Axboecbb7e572006-04-11 14:57:50 +0200371 pipe, count, *ppos, ioflags);
372 ret = generic_file_splice_read(infilp, ppos, pipe, count, flags);
Nathan Scott1b895842006-03-31 13:08:59 +1000373 if (ret > 0)
374 XFS_STATS_ADD(xs_read_bytes, ret);
375
376 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
377 return ret;
378}
379
380ssize_t
381xfs_splice_write(
382 bhv_desc_t *bdp,
Ingo Molnar3a326a22006-04-10 15:18:35 +0200383 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000384 struct file *outfilp,
Jens Axboecbb7e572006-04-11 14:57:50 +0200385 loff_t *ppos,
Nathan Scott1b895842006-03-31 13:08:59 +1000386 size_t count,
387 int flags,
388 int ioflags,
389 cred_t *credp)
390{
391 xfs_inode_t *ip = XFS_BHVTOI(bdp);
392 xfs_mount_t *mp = ip->i_mount;
393 ssize_t ret;
394
395 XFS_STATS_INC(xs_write_calls);
396 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
397 return -EIO;
398
399 xfs_ilock(ip, XFS_IOLOCK_EXCL);
400
401 if (DM_EVENT_ENABLED(BHV_TO_VNODE(bdp)->v_vfsp, ip, DM_EVENT_WRITE) &&
402 (!(ioflags & IO_INVIS))) {
Nathan Scott8285fb52006-06-09 17:07:12 +1000403 bhv_vrwlock_t locktype = VRWLOCK_WRITE;
Nathan Scott1b895842006-03-31 13:08:59 +1000404 int error;
405
406 error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, BHV_TO_VNODE(bdp),
Jens Axboecbb7e572006-04-11 14:57:50 +0200407 *ppos, count,
Nathan Scott1b895842006-03-31 13:08:59 +1000408 FILP_DELAY_FLAG(outfilp), &locktype);
409 if (error) {
410 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
411 return -error;
412 }
413 }
414 xfs_rw_enter_trace(XFS_SPLICE_WRITE_ENTER, &ip->i_iocore,
Jens Axboecbb7e572006-04-11 14:57:50 +0200415 pipe, count, *ppos, ioflags);
416 ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags);
Nathan Scott1b895842006-03-31 13:08:59 +1000417 if (ret > 0)
418 XFS_STATS_ADD(xs_write_bytes, ret);
419
420 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 return ret;
422}
423
424/*
425 * This routine is called to handle zeroing any space in the last
426 * block of the file that is beyond the EOF. We do this since the
427 * size is being increased without writing anything to that block
428 * and we don't want anyone to read the garbage on the disk.
429 */
430STATIC int /* error (positive) */
431xfs_zero_last_block(
432 struct inode *ip,
433 xfs_iocore_t *io,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 xfs_fsize_t isize,
435 xfs_fsize_t end_size)
436{
437 xfs_fileoff_t last_fsb;
Nathan Scott1b895842006-03-31 13:08:59 +1000438 xfs_mount_t *mp = io->io_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 int nimaps;
440 int zero_offset;
441 int zero_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 int error = 0;
443 xfs_bmbt_irec_t imap;
444 loff_t loff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 ASSERT(ismrlocked(io->io_lock, MR_UPDATE) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Eric Sandeen24ee8082006-01-11 15:34:32 +1100448 zero_offset = XFS_B_FSB_OFFSET(mp, isize);
449 if (zero_offset == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 /*
451 * There are no extra bytes in the last block on disk to
452 * zero, so return.
453 */
454 return 0;
455 }
456
457 last_fsb = XFS_B_TO_FSBT(mp, isize);
458 nimaps = 1;
459 error = XFS_BMAPI(mp, NULL, io, last_fsb, 1, 0, NULL, 0, &imap,
Olaf Weber3e57ecf2006-06-09 14:48:12 +1000460 &nimaps, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 if (error) {
462 return error;
463 }
464 ASSERT(nimaps > 0);
465 /*
466 * If the block underlying isize is just a hole, then there
467 * is nothing to zero.
468 */
469 if (imap.br_startblock == HOLESTARTBLOCK) {
470 return 0;
471 }
472 /*
473 * Zero the part of the last block beyond the EOF, and write it
474 * out sync. We need to drop the ilock while we do this so we
475 * don't deadlock when the buffer cache calls back to us.
476 */
477 XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL| XFS_EXTSIZE_RD);
Nathan Scott1b895842006-03-31 13:08:59 +1000478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 loff = XFS_FSB_TO_B(mp, last_fsb);
Eric Sandeen24ee8082006-01-11 15:34:32 +1100480 zero_len = mp->m_sb.sb_blocksize - zero_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 error = xfs_iozero(ip, loff + zero_offset, zero_len, end_size);
482
483 XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
484 ASSERT(error >= 0);
485 return error;
486}
487
488/*
489 * Zero any on disk space between the current EOF and the new,
490 * larger EOF. This handles the normal case of zeroing the remainder
491 * of the last block in the file and the unusual case of zeroing blocks
492 * out beyond the size of the file. This second case only happens
493 * with fixed size extents and when the system crashes before the inode
494 * size was updated but after blocks were allocated. If fill is set,
495 * then any holes in the range are filled and zeroed. If not, the holes
496 * are left alone as holes.
497 */
498
499int /* error (positive) */
500xfs_zero_eof(
Nathan Scott67fcaa72006-06-09 17:00:52 +1000501 bhv_vnode_t *vp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 xfs_iocore_t *io,
503 xfs_off_t offset, /* starting I/O offset */
504 xfs_fsize_t isize, /* current inode size */
505 xfs_fsize_t end_size) /* terminal inode size */
506{
Nathan Scottec86dc02006-03-17 17:25:36 +1100507 struct inode *ip = vn_to_inode(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 xfs_fileoff_t start_zero_fsb;
509 xfs_fileoff_t end_zero_fsb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 xfs_fileoff_t zero_count_fsb;
511 xfs_fileoff_t last_fsb;
Nathan Scott1b895842006-03-31 13:08:59 +1000512 xfs_mount_t *mp = io->io_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 int nimaps;
514 int error = 0;
515 xfs_bmbt_irec_t imap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
518 ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
Eric Sandeen24ee8082006-01-11 15:34:32 +1100519 ASSERT(offset > isize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 /*
522 * First handle zeroing the block on which isize resides.
523 * We only zero a part of that block so it is handled specially.
524 */
Eric Sandeen24ee8082006-01-11 15:34:32 +1100525 error = xfs_zero_last_block(ip, io, isize, end_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (error) {
527 ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
528 ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
529 return error;
530 }
531
532 /*
533 * Calculate the range between the new size and the old
534 * where blocks needing to be zeroed may exist. To get the
535 * block where the last byte in the file currently resides,
536 * we need to subtract one from the size and truncate back
537 * to a block boundary. We subtract 1 in case the size is
538 * exactly on a block boundary.
539 */
540 last_fsb = isize ? XFS_B_TO_FSBT(mp, isize - 1) : (xfs_fileoff_t)-1;
541 start_zero_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)isize);
542 end_zero_fsb = XFS_B_TO_FSBT(mp, offset - 1);
543 ASSERT((xfs_sfiloff_t)last_fsb < (xfs_sfiloff_t)start_zero_fsb);
544 if (last_fsb == end_zero_fsb) {
545 /*
546 * The size was only incremented on its last block.
547 * We took care of that above, so just return.
548 */
549 return 0;
550 }
551
552 ASSERT(start_zero_fsb <= end_zero_fsb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 while (start_zero_fsb <= end_zero_fsb) {
554 nimaps = 1;
555 zero_count_fsb = end_zero_fsb - start_zero_fsb + 1;
556 error = XFS_BMAPI(mp, NULL, io, start_zero_fsb, zero_count_fsb,
Olaf Weber3e57ecf2006-06-09 14:48:12 +1000557 0, NULL, 0, &imap, &nimaps, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 if (error) {
559 ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
560 ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
561 return error;
562 }
563 ASSERT(nimaps > 0);
564
565 if (imap.br_state == XFS_EXT_UNWRITTEN ||
566 imap.br_startblock == HOLESTARTBLOCK) {
567 /*
568 * This loop handles initializing pages that were
569 * partially initialized by the code below this
570 * loop. It basically zeroes the part of the page
571 * that sits on a hole and sets the page as P_HOLE
572 * and calls remapf if it is a mapped file.
573 */
Eric Sandeen24ee8082006-01-11 15:34:32 +1100574 start_zero_fsb = imap.br_startoff + imap.br_blockcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
576 continue;
577 }
578
579 /*
Nathan Scott3d80ede2006-06-09 14:57:30 +1000580 * There are blocks we need to zero.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 * Drop the inode lock while we're doing the I/O.
582 * We'll still have the iolock to protect us.
583 */
584 XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
585
Eric Sandeen24ee8082006-01-11 15:34:32 +1100586 error = xfs_iozero(ip,
587 XFS_FSB_TO_B(mp, start_zero_fsb),
Nathan Scott3d80ede2006-06-09 14:57:30 +1000588 XFS_FSB_TO_B(mp, imap.br_blockcount),
Eric Sandeen24ee8082006-01-11 15:34:32 +1100589 end_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 if (error) {
591 goto out_lock;
592 }
593
Nathan Scott3d80ede2006-06-09 14:57:30 +1000594 start_zero_fsb = imap.br_startoff + imap.br_blockcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
596
597 XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
598 }
599
600 return 0;
601
602out_lock:
603
604 XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
605 ASSERT(error >= 0);
606 return error;
607}
608
609ssize_t /* bytes written, or (-) error */
610xfs_write(
611 bhv_desc_t *bdp,
612 struct kiocb *iocb,
613 const struct iovec *iovp,
614 unsigned int nsegs,
615 loff_t *offset,
616 int ioflags,
617 cred_t *credp)
618{
619 struct file *file = iocb->ki_filp;
620 struct address_space *mapping = file->f_mapping;
621 struct inode *inode = mapping->host;
622 unsigned long segs = nsegs;
623 xfs_inode_t *xip;
624 xfs_mount_t *mp;
625 ssize_t ret = 0, error = 0;
626 xfs_fsize_t isize, new_size;
627 xfs_iocore_t *io;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000628 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 unsigned long seg;
630 int iolock;
631 int eventsent = 0;
Nathan Scott8285fb52006-06-09 17:07:12 +1000632 bhv_vrwlock_t locktype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 size_t ocount = 0, count;
634 loff_t pos;
Nathan Scotta13828b2006-03-17 17:26:14 +1100635 int need_i_mutex = 1, need_flush = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 XFS_STATS_INC(xs_write_calls);
638
639 vp = BHV_TO_VNODE(bdp);
640 xip = XFS_BHVTOI(bdp);
641
642 for (seg = 0; seg < segs; seg++) {
643 const struct iovec *iv = &iovp[seg];
644
645 /*
646 * If any segment has a negative length, or the cumulative
647 * length ever wraps negative then return -EINVAL.
648 */
649 ocount += iv->iov_len;
650 if (unlikely((ssize_t)(ocount|iv->iov_len) < 0))
651 return -EINVAL;
652 if (access_ok(VERIFY_READ, iv->iov_base, iv->iov_len))
653 continue;
654 if (seg == 0)
655 return -EFAULT;
656 segs = seg;
657 ocount -= iv->iov_len; /* This segment is no good */
658 break;
659 }
660
661 count = ocount;
662 pos = *offset;
663
664 if (count == 0)
665 return 0;
666
667 io = &xip->i_iocore;
668 mp = io->io_mount;
669
Nathan Scott34327e12006-06-09 17:11:55 +1000670 vfs_wait_for_freeze(vp->v_vfsp, SB_FREEZE_WRITE);
671
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 if (XFS_FORCED_SHUTDOWN(mp))
673 return -EIO;
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 if (ioflags & IO_ISDIRECT) {
676 xfs_buftarg_t *target =
677 (xip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
678 mp->m_rtdev_targp : mp->m_ddev_targp;
679
Nathan Scottce8e9222006-01-11 15:39:08 +1100680 if ((pos & target->bt_smask) || (count & target->bt_smask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 return XFS_ERROR(-EINVAL);
682
683 if (!VN_CACHED(vp) && pos < i_size_read(inode))
Nathan Scotta13828b2006-03-17 17:26:14 +1100684 need_i_mutex = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
686 if (VN_CACHED(vp))
687 need_flush = 1;
688 }
689
690relock:
Nathan Scotta13828b2006-03-17 17:26:14 +1100691 if (need_i_mutex) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 iolock = XFS_IOLOCK_EXCL;
693 locktype = VRWLOCK_WRITE;
694
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800695 mutex_lock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 } else {
697 iolock = XFS_IOLOCK_SHARED;
698 locktype = VRWLOCK_WRITE_DIRECT;
699 }
700
701 xfs_ilock(xip, XFS_ILOCK_EXCL|iolock);
702
703 isize = i_size_read(inode);
704
705 if (file->f_flags & O_APPEND)
706 *offset = isize;
707
708start:
709 error = -generic_write_checks(file, &pos, &count,
710 S_ISBLK(inode->i_mode));
711 if (error) {
712 xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
Nathan Scotta13828b2006-03-17 17:26:14 +1100713 goto out_unlock_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
715
716 new_size = pos + count;
717 if (new_size > isize)
718 io->io_new_size = new_size;
719
720 if ((DM_EVENT_ENABLED(vp->v_vfsp, xip, DM_EVENT_WRITE) &&
721 !(ioflags & IO_INVIS) && !eventsent)) {
722 loff_t savedsize = pos;
723 int dmflags = FILP_DELAY_FLAG(file);
724
Nathan Scotta13828b2006-03-17 17:26:14 +1100725 if (need_i_mutex)
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800726 dmflags |= DM_FLAGS_IMUX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 xfs_iunlock(xip, XFS_ILOCK_EXCL);
729 error = XFS_SEND_DATA(xip->i_mount, DM_EVENT_WRITE, vp,
730 pos, count,
731 dmflags, &locktype);
732 if (error) {
733 xfs_iunlock(xip, iolock);
Nathan Scotta13828b2006-03-17 17:26:14 +1100734 goto out_unlock_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 }
736 xfs_ilock(xip, XFS_ILOCK_EXCL);
737 eventsent = 1;
738
739 /*
Nathan Scottc41564b2006-03-29 08:55:14 +1000740 * The iolock was dropped and reacquired in XFS_SEND_DATA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 * so we have to recheck the size when appending.
742 * We will only "goto start;" once, since having sent the
743 * event prevents another call to XFS_SEND_DATA, which is
744 * what allows the size to change in the first place.
745 */
746 if ((file->f_flags & O_APPEND) && savedsize != isize) {
747 pos = isize = xip->i_d.di_size;
748 goto start;
749 }
750 }
751
Nathan Scott4aeb6642005-11-02 11:43:58 +1100752 if (likely(!(ioflags & IO_INVIS))) {
Christoph Hellwig870f4812006-01-09 20:52:01 -0800753 file_update_time(file);
Nathan Scott4aeb6642005-11-02 11:43:58 +1100754 xfs_ichgtime_fast(xip, inode,
755 XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
757
758 /*
759 * If the offset is beyond the size of the file, we have a couple
760 * of things to do. First, if there is already space allocated
761 * we need to either create holes or zero the disk or ...
762 *
763 * If there is a page where the previous size lands, we need
764 * to zero it out up to the new size.
765 */
766
767 if (pos > isize) {
768 error = xfs_zero_eof(BHV_TO_VNODE(bdp), io, pos,
769 isize, pos + count);
770 if (error) {
771 xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
Nathan Scotta13828b2006-03-17 17:26:14 +1100772 goto out_unlock_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 }
774 }
775 xfs_iunlock(xip, XFS_ILOCK_EXCL);
776
777 /*
778 * If we're writing the file then make sure to clear the
779 * setuid and setgid bits if the process is not being run
780 * by root. This keeps people from modifying setuid and
781 * setgid binaries.
782 */
783
784 if (((xip->i_d.di_mode & S_ISUID) ||
785 ((xip->i_d.di_mode & (S_ISGID | S_IXGRP)) ==
786 (S_ISGID | S_IXGRP))) &&
787 !capable(CAP_FSETID)) {
788 error = xfs_write_clear_setuid(xip);
789 if (likely(!error))
790 error = -remove_suid(file->f_dentry);
791 if (unlikely(error)) {
792 xfs_iunlock(xip, iolock);
Nathan Scotta13828b2006-03-17 17:26:14 +1100793 goto out_unlock_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 }
795 }
796
797retry:
798 /* We can write back this queue in page reclaim */
799 current->backing_dev_info = mapping->backing_dev_info;
800
801 if ((ioflags & IO_ISDIRECT)) {
802 if (need_flush) {
803 xfs_inval_cached_trace(io, pos, -1,
804 ctooff(offtoct(pos)), -1);
Nathan Scott67fcaa72006-06-09 17:00:52 +1000805 bhv_vop_flushinval_pages(vp, ctooff(offtoct(pos)),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 -1, FI_REMAPF_LOCKED);
807 }
808
Nathan Scotta13828b2006-03-17 17:26:14 +1100809 if (need_i_mutex) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 /* demote the lock now the cached pages are gone */
811 XFS_ILOCK_DEMOTE(mp, io, XFS_IOLOCK_EXCL);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800812 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 iolock = XFS_IOLOCK_SHARED;
815 locktype = VRWLOCK_WRITE_DIRECT;
Nathan Scotta13828b2006-03-17 17:26:14 +1100816 need_i_mutex = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 }
818
819 xfs_rw_enter_trace(XFS_DIOWR_ENTER, io, (void *)iovp, segs,
820 *offset, ioflags);
821 ret = generic_file_direct_write(iocb, iovp,
822 &segs, pos, offset, count, ocount);
823
824 /*
825 * direct-io write to a hole: fall through to buffered I/O
826 * for completing the rest of the request.
827 */
828 if (ret >= 0 && ret != count) {
829 XFS_STATS_ADD(xs_write_bytes, ret);
830
831 pos += ret;
832 count -= ret;
833
Nathan Scotta13828b2006-03-17 17:26:14 +1100834 need_i_mutex = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 ioflags &= ~IO_ISDIRECT;
836 xfs_iunlock(xip, iolock);
837 goto relock;
838 }
839 } else {
840 xfs_rw_enter_trace(XFS_WRITE_ENTER, io, (void *)iovp, segs,
841 *offset, ioflags);
842 ret = generic_file_buffered_write(iocb, iovp, segs,
843 pos, offset, count, ret);
844 }
845
846 current->backing_dev_info = NULL;
847
848 if (ret == -EIOCBQUEUED && !(ioflags & IO_ISAIO))
849 ret = wait_on_sync_kiocb(iocb);
850
851 if ((ret == -ENOSPC) &&
852 DM_EVENT_ENABLED(vp->v_vfsp, xip, DM_EVENT_NOSPACE) &&
853 !(ioflags & IO_INVIS)) {
854
855 xfs_rwunlock(bdp, locktype);
Nathan Scotta13828b2006-03-17 17:26:14 +1100856 if (need_i_mutex)
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800857 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 error = XFS_SEND_NAMESP(xip->i_mount, DM_EVENT_NOSPACE, vp,
859 DM_RIGHT_NULL, vp, DM_RIGHT_NULL, NULL, NULL,
860 0, 0, 0); /* Delay flag intentionally unused */
861 if (error)
Dean Roehriche1a40fa2005-06-22 10:20:44 +1000862 goto out_nounlocks;
Nathan Scotta13828b2006-03-17 17:26:14 +1100863 if (need_i_mutex)
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800864 mutex_lock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 xfs_rwlock(bdp, locktype);
866 pos = xip->i_d.di_size;
867 ret = 0;
868 goto retry;
869 }
870
Yingping Lu68bdb6e2006-01-11 15:38:31 +1100871 isize = i_size_read(inode);
872 if (unlikely(ret < 0 && ret != -EFAULT && *offset > isize))
873 *offset = isize;
874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 if (*offset > xip->i_d.di_size) {
876 xfs_ilock(xip, XFS_ILOCK_EXCL);
877 if (*offset > xip->i_d.di_size) {
878 xip->i_d.di_size = *offset;
879 i_size_write(inode, *offset);
880 xip->i_update_core = 1;
881 xip->i_update_size = 1;
882 }
883 xfs_iunlock(xip, XFS_ILOCK_EXCL);
884 }
885
886 error = -ret;
887 if (ret <= 0)
888 goto out_unlock_internal;
889
890 XFS_STATS_ADD(xs_write_bytes, ret);
891
892 /* Handle various SYNC-type writes */
893 if ((file->f_flags & O_SYNC) || IS_SYNC(inode)) {
Nathan Scott1e69dd02006-06-19 08:39:53 +1000894 error = xfs_write_sync_logforce(mp, xip);
895 if (error)
896 goto out_unlock_internal;
Nathan Scotta13828b2006-03-17 17:26:14 +1100897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 xfs_rwunlock(bdp, locktype);
Nathan Scotta13828b2006-03-17 17:26:14 +1100899 if (need_i_mutex)
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800900 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902 error = sync_page_range(inode, mapping, pos, ret);
903 if (!error)
904 error = ret;
905 return error;
906 }
907
908 out_unlock_internal:
909 xfs_rwunlock(bdp, locktype);
Nathan Scotta13828b2006-03-17 17:26:14 +1100910 out_unlock_mutex:
911 if (need_i_mutex)
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800912 mutex_unlock(&inode->i_mutex);
Dean Roehriche1a40fa2005-06-22 10:20:44 +1000913 out_nounlocks:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 return -error;
915}
916
917/*
918 * All xfs metadata buffers except log state machine buffers
919 * get this attached as their b_bdstrat callback function.
920 * This is so that we can catch a buffer
921 * after prematurely unpinning it to forcibly shutdown the filesystem.
922 */
923int
924xfs_bdstrat_cb(struct xfs_buf *bp)
925{
926 xfs_mount_t *mp;
927
928 mp = XFS_BUF_FSPRIVATE3(bp, xfs_mount_t *);
929 if (!XFS_FORCED_SHUTDOWN(mp)) {
Nathan Scottce8e9222006-01-11 15:39:08 +1100930 xfs_buf_iorequest(bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 return 0;
932 } else {
933 xfs_buftrace("XFS__BDSTRAT IOERROR", bp);
934 /*
935 * Metadata write that didn't get logged but
936 * written delayed anyway. These aren't associated
937 * with a transaction, and can be ignored.
938 */
939 if (XFS_BUF_IODONE_FUNC(bp) == NULL &&
940 (XFS_BUF_ISREAD(bp)) == 0)
941 return (xfs_bioerror_relse(bp));
942 else
943 return (xfs_bioerror(bp));
944 }
945}
946
947
948int
949xfs_bmap(bhv_desc_t *bdp,
950 xfs_off_t offset,
951 ssize_t count,
952 int flags,
953 xfs_iomap_t *iomapp,
954 int *niomaps)
955{
956 xfs_inode_t *ip = XFS_BHVTOI(bdp);
957 xfs_iocore_t *io = &ip->i_iocore;
958
959 ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG);
960 ASSERT(((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) != 0) ==
961 ((ip->i_iocore.io_flags & XFS_IOCORE_RT) != 0));
962
963 return xfs_iomap(io, offset, count, flags, iomapp, niomaps);
964}
965
966/*
967 * Wrapper around bdstrat so that we can stop data
968 * from going to disk in case we are shutting down the filesystem.
969 * Typically user data goes thru this path; one of the exceptions
970 * is the superblock.
971 */
972int
973xfsbdstrat(
974 struct xfs_mount *mp,
975 struct xfs_buf *bp)
976{
977 ASSERT(mp);
978 if (!XFS_FORCED_SHUTDOWN(mp)) {
979 /* Grio redirection would go here
980 * if (XFS_BUF_IS_GRIO(bp)) {
981 */
982
Nathan Scottce8e9222006-01-11 15:39:08 +1100983 xfs_buf_iorequest(bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 return 0;
985 }
986
987 xfs_buftrace("XFSBDSTRAT IOERROR", bp);
988 return (xfs_bioerror_relse(bp));
989}
990
991/*
992 * If the underlying (data/log/rt) device is readonly, there are some
993 * operations that cannot proceed.
994 */
995int
996xfs_dev_is_read_only(
997 xfs_mount_t *mp,
998 char *message)
999{
1000 if (xfs_readonly_buftarg(mp->m_ddev_targp) ||
1001 xfs_readonly_buftarg(mp->m_logdev_targp) ||
1002 (mp->m_rtdev_targp && xfs_readonly_buftarg(mp->m_rtdev_targp))) {
1003 cmn_err(CE_NOTE,
1004 "XFS: %s required on read-only device.", message);
1005 cmn_err(CE_NOTE,
1006 "XFS: write access unavailable, cannot proceed.");
1007 return EROFS;
1008 }
1009 return 0;
1010}