| .. | .. |
|---|
| 2 | 2 | /* |
|---|
| 3 | 3 | * Copyright (c) 2014 Christoph Hellwig. |
|---|
| 4 | 4 | */ |
|---|
| 5 | | -#include <linux/iomap.h> |
|---|
| 6 | 5 | #include "xfs.h" |
|---|
| 6 | +#include "xfs_shared.h" |
|---|
| 7 | 7 | #include "xfs_format.h" |
|---|
| 8 | 8 | #include "xfs_log_format.h" |
|---|
| 9 | 9 | #include "xfs_trans_resv.h" |
|---|
| 10 | | -#include "xfs_sb.h" |
|---|
| 11 | 10 | #include "xfs_mount.h" |
|---|
| 12 | 11 | #include "xfs_inode.h" |
|---|
| 13 | 12 | #include "xfs_trans.h" |
|---|
| 14 | | -#include "xfs_log.h" |
|---|
| 15 | 13 | #include "xfs_bmap.h" |
|---|
| 16 | | -#include "xfs_bmap_util.h" |
|---|
| 17 | | -#include "xfs_error.h" |
|---|
| 18 | 14 | #include "xfs_iomap.h" |
|---|
| 19 | | -#include "xfs_shared.h" |
|---|
| 20 | | -#include "xfs_bit.h" |
|---|
| 21 | 15 | #include "xfs_pnfs.h" |
|---|
| 22 | 16 | |
|---|
| 23 | 17 | /* |
|---|
| .. | .. |
|---|
| 39 | 33 | struct xfs_inode *ip = XFS_I(inode); |
|---|
| 40 | 34 | int error; |
|---|
| 41 | 35 | |
|---|
| 42 | | - while ((error = break_layout(inode, false) == -EWOULDBLOCK)) { |
|---|
| 36 | + while ((error = break_layout(inode, false)) == -EWOULDBLOCK) { |
|---|
| 43 | 37 | xfs_iunlock(ip, *iolock); |
|---|
| 44 | 38 | *did_unlock = true; |
|---|
| 45 | 39 | error = break_layout(inode, true); |
|---|
| .. | .. |
|---|
| 64 | 58 | { |
|---|
| 65 | 59 | struct xfs_mount *mp = XFS_M(sb); |
|---|
| 66 | 60 | |
|---|
| 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!"); |
|---|
| 70 | 63 | |
|---|
| 71 | 64 | if (*len < sizeof(uuid_t)) |
|---|
| 72 | 65 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 149 | 142 | lock_flags = xfs_ilock_data_map_shared(ip); |
|---|
| 150 | 143 | error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, |
|---|
| 151 | 144 | &imap, &nimaps, bmapi_flags); |
|---|
| 152 | | - xfs_iunlock(ip, lock_flags); |
|---|
| 153 | 145 | |
|---|
| 154 | | - if (error) |
|---|
| 155 | | - goto out_unlock; |
|---|
| 146 | + ASSERT(!nimaps || imap.br_startblock != DELAYSTARTBLOCK); |
|---|
| 156 | 147 | |
|---|
| 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); |
|---|
| 159 | 156 | |
|---|
| 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); |
|---|
| 183 | 159 | if (error) |
|---|
| 184 | 160 | 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); |
|---|
| 185 | 175 | } |
|---|
| 186 | 176 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); |
|---|
| 187 | 177 | |
|---|
| 188 | | - xfs_bmbt_to_iomap(ip, iomap, &imap); |
|---|
| 178 | + error = xfs_bmbt_to_iomap(ip, iomap, &imap, 0); |
|---|
| 189 | 179 | *device_generation = mp->m_generation; |
|---|
| 190 | 180 | return error; |
|---|
| 191 | 181 | out_unlock: |
|---|
| .. | .. |
|---|
| 295 | 285 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); |
|---|
| 296 | 286 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
|---|
| 297 | 287 | |
|---|
| 298 | | - xfs_setattr_time(ip, iattr); |
|---|
| 288 | + ASSERT(!(iattr->ia_valid & (ATTR_UID | ATTR_GID))); |
|---|
| 289 | + setattr_copy(inode, iattr); |
|---|
| 299 | 290 | if (update_isize) { |
|---|
| 300 | 291 | i_size_write(inode, iattr->ia_size); |
|---|
| 301 | 292 | ip->i_d.di_size = iattr->ia_size; |
|---|