aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2015-04-05 14:06:24 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2015-04-11 22:29:46 -0400
commitccca26835dc27f7ba54e09d7aa03f462684a1927 (patch)
tree0232a749ec6a721e1acbe389ff9de680d312168c /fs
parentf765b134c0d3f294f6084d3e0a11de184059a387 (diff)
ntfs: move iov_iter_truncate() closer to generic_write_checks()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r--fs/ntfs/file.c81
1 files changed, 29 insertions, 52 deletions
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 840e95e3f1d2..77087d5ad458 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -328,26 +328,29 @@ err_out:
328 return err; 328 return err;
329} 329}
330 330
331static ssize_t ntfs_prepare_file_for_write(struct file *file, loff_t *ppos, 331static ssize_t ntfs_prepare_file_for_write(struct kiocb *iocb,
332 size_t *count) 332 struct iov_iter *from)
333{ 333{
334 loff_t pos; 334 loff_t pos;
335 s64 end, ll; 335 s64 end, ll;
336 ssize_t err; 336 ssize_t err;
337 unsigned long flags; 337 unsigned long flags;
338 struct file *file = iocb->ki_filp;
338 struct inode *vi = file_inode(file); 339 struct inode *vi = file_inode(file);
339 ntfs_inode *base_ni, *ni = NTFS_I(vi); 340 ntfs_inode *base_ni, *ni = NTFS_I(vi);
340 ntfs_volume *vol = ni->vol; 341 ntfs_volume *vol = ni->vol;
342 size_t count = iov_iter_count(from);
341 343
342 ntfs_debug("Entering for i_ino 0x%lx, attribute type 0x%x, pos " 344 ntfs_debug("Entering for i_ino 0x%lx, attribute type 0x%x, pos "
343 "0x%llx, count 0x%lx.", vi->i_ino, 345 "0x%llx, count 0x%zx.", vi->i_ino,
344 (unsigned)le32_to_cpu(ni->type), 346 (unsigned)le32_to_cpu(ni->type),
345 (unsigned long long)*ppos, (unsigned long)*count); 347 (unsigned long long)iocb->ki_pos, count);
346 /* We can write back this queue in page reclaim. */ 348 err = generic_write_checks(file, &iocb->ki_pos, &count, S_ISBLK(vi->i_mode));
347 current->backing_dev_info = inode_to_bdi(vi);
348 err = generic_write_checks(file, ppos, count, S_ISBLK(vi->i_mode));
349 if (unlikely(err)) 349 if (unlikely(err))
350 goto out; 350 goto out;
351 iov_iter_truncate(from, count);
352 if (count == 0)
353 goto out;
351 /* 354 /*
352 * All checks have passed. Before we start doing any writing we want 355 * All checks have passed. Before we start doing any writing we want
353 * to abort any totally illegal writes. 356 * to abort any totally illegal writes.
@@ -379,8 +382,6 @@ static ssize_t ntfs_prepare_file_for_write(struct file *file, loff_t *ppos,
379 err = -EOPNOTSUPP; 382 err = -EOPNOTSUPP;
380 goto out; 383 goto out;
381 } 384 }
382 if (*count == 0)
383 goto out;
384 base_ni = ni; 385 base_ni = ni;
385 if (NInoAttr(ni)) 386 if (NInoAttr(ni))
386 base_ni = ni->ext.base_ntfs_ino; 387 base_ni = ni->ext.base_ntfs_ino;
@@ -392,9 +393,9 @@ static ssize_t ntfs_prepare_file_for_write(struct file *file, loff_t *ppos,
392 * cannot fail either so there is no need to check the return code. 393 * cannot fail either so there is no need to check the return code.
393 */ 394 */
394 file_update_time(file); 395 file_update_time(file);
395 pos = *ppos; 396 pos = iocb->ki_pos;
396 /* The first byte after the last cluster being written to. */ 397 /* The first byte after the last cluster being written to. */
397 end = (pos + *count + vol->cluster_size_mask) & 398 end = (pos + iov_iter_count(from) + vol->cluster_size_mask) &
398 ~(u64)vol->cluster_size_mask; 399 ~(u64)vol->cluster_size_mask;
399 /* 400 /*
400 * If the write goes beyond the allocated size, extend the allocation 401 * If the write goes beyond the allocated size, extend the allocation
@@ -422,7 +423,7 @@ static ssize_t ntfs_prepare_file_for_write(struct file *file, loff_t *ppos,
422 "partially extended.", 423 "partially extended.",
423 vi->i_ino, (unsigned) 424 vi->i_ino, (unsigned)
424 le32_to_cpu(ni->type)); 425 le32_to_cpu(ni->type));
425 *count = ll - pos; 426 iov_iter_truncate(from, ll - pos);
426 } 427 }
427 } else { 428 } else {
428 err = ll; 429 err = ll;
@@ -438,7 +439,7 @@ static ssize_t ntfs_prepare_file_for_write(struct file *file, loff_t *ppos,
438 vi->i_ino, (unsigned) 439 vi->i_ino, (unsigned)
439 le32_to_cpu(ni->type), 440 le32_to_cpu(ni->type),
440 (int)-err); 441 (int)-err);
441 *count = ll - pos; 442 iov_iter_truncate(from, ll - pos);
442 } else { 443 } else {
443 if (err != -ENOSPC) 444 if (err != -ENOSPC)
444 ntfs_error(vi->i_sb, "Cannot perform " 445 ntfs_error(vi->i_sb, "Cannot perform "
@@ -1930,60 +1931,36 @@ again:
1930} 1931}
1931 1932
1932/** 1933/**
1933 * ntfs_file_write_iter_nolock - write data to a file
1934 * @iocb: IO state structure (file, offset, etc.)
1935 * @from: iov_iter with data to write
1936 *
1937 * Basically the same as __generic_file_write_iter() except that it ends
1938 * up calling ntfs_perform_write() instead of generic_perform_write() and that
1939 * O_DIRECT is not implemented.
1940 */
1941static ssize_t ntfs_file_write_iter_nolock(struct kiocb *iocb,
1942 struct iov_iter *from)
1943{
1944 struct file *file = iocb->ki_filp;
1945 loff_t pos = iocb->ki_pos;
1946 ssize_t written = 0;
1947 ssize_t err;
1948 size_t count = iov_iter_count(from);
1949
1950 err = ntfs_prepare_file_for_write(file, &pos, &count);
1951 if (count && !err) {
1952 iov_iter_truncate(from, count);
1953 written = ntfs_perform_write(file, from, pos);
1954 if (likely(written >= 0))
1955 iocb->ki_pos = pos + written;
1956 }
1957 current->backing_dev_info = NULL;
1958 return written ? written : err;
1959}
1960
1961/**
1962 * ntfs_file_write_iter - simple wrapper for ntfs_file_write_iter_nolock() 1934 * ntfs_file_write_iter - simple wrapper for ntfs_file_write_iter_nolock()
1963 * @iocb: IO state structure 1935 * @iocb: IO state structure
1964 * @from: iov_iter with data to write 1936 * @from: iov_iter with data to write
1965 * 1937 *
1966 * Basically the same as generic_file_write_iter() except that it ends up 1938 * Basically the same as generic_file_write_iter() except that it ends up
1967 * calling ntfs_file_write_iter_nolock() instead of 1939 * up calling ntfs_perform_write() instead of generic_perform_write() and that
1968 * __generic_file_write_iter(). 1940 * O_DIRECT is not implemented.
1969 */ 1941 */
1970static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) 1942static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
1971{ 1943{
1972 struct file *file = iocb->ki_filp; 1944 struct file *file = iocb->ki_filp;
1973 struct inode *vi = file_inode(file); 1945 struct inode *vi = file_inode(file);
1974 ssize_t ret; 1946 ssize_t written = 0;
1947 ssize_t err;
1975 1948
1976 mutex_lock(&vi->i_mutex); 1949 mutex_lock(&vi->i_mutex);
1977 ret = ntfs_file_write_iter_nolock(iocb, from); 1950 /* We can write back this queue in page reclaim. */
1951 current->backing_dev_info = inode_to_bdi(vi);
1952 err = ntfs_prepare_file_for_write(iocb, from);
1953 if (iov_iter_count(from) && !err)
1954 written = ntfs_perform_write(file, from, iocb->ki_pos);
1955 current->backing_dev_info = NULL;
1978 mutex_unlock(&vi->i_mutex); 1956 mutex_unlock(&vi->i_mutex);
1979 if (ret > 0) { 1957 if (likely(written > 0)) {
1980 ssize_t err; 1958 err = generic_write_sync(file, iocb->ki_pos, written);
1981
1982 err = generic_write_sync(file, iocb->ki_pos - ret, ret);
1983 if (err < 0) 1959 if (err < 0)
1984 ret = err; 1960 written = 0;
1985 } 1961 }
1986 return ret; 1962 iocb->ki_pos += written;
1963 return written ? written : err;
1987} 1964}
1988 1965
1989/** 1966/**