aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-11-14 16:55:51 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-11-14 16:55:51 -0500
commit29309a4eb8a2a9163b20657ce30510406c792d79 (patch)
tree629caeb53de69e00627fa0a51cf1d95b6d353a2f
parentac446dcc8360b3d31a87f0c6390ab75a18fc44ba (diff)
parentd0920a9cd7e735c429c510b523a100db82c937a1 (diff)
Merge tag 'gfs2-4.15.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2
Pull gfs2 updates from Bob Peterson: "We've got a total of 17 GFS2 patches for this merge window. The patches are basically in three categories: (1) patches related to broken xfstest cases, (2) patches related to improving iomap and start using it in GFS2, and (3) general typos and clarifications. Please note that one of the iomap patches extends beyond GFS2 and affects other file systems, but it was publically reviewed by a variety of file system people in the community. From Andreas Gruenbacher: - rename variable 'bsize' to 'factor' to clarify the logic related to gfs2_block_map. - correctly set ctime in the setflags ioctl, which fixes broken xfstests test 277. - fix broken xfstest 258, due to an atime initialization problem. - fix broken xfstest 307, in which GFS2 was not setting ctime when setting acls. - switch general iomap code from blkno to disk offset for a variety of file systems. - add a new IOMAP_F_DATA_INLINE flag for iomap to indicate blocks that have data mixed with metadata. - implement SEEK_HOLE and SEEK_DATA via iomap in GFS2. - fix failing xfstest case 066, which was due to not properly syncing dirty inodes when changing extended attributes. - fix a minor typo in a comment. - partially fix xfstest 424, which involved GET_FLAGS and SET_FLAGS ioctl. This is also a cleanup and simplification of the translation of flags from fs flags to gfs2 flags. - add support for STATX_ATTR_ in statx, which fixed broken xfstest 424. - fix for failing xfstest 093 which fixes a recursive glock problem with gfs2_xattr_get and _set From me: - make inode height info part of the 'metapath' data structure to facilitate using iomap in GFS2. - start using iomap inside GFS2 and switch GFS2's block_map functions to use iomap under the covers. - switch GFS2's fiemap implementation from using block_map to using iomap under the covers. - fix journaled data pages not being properly synced to media when writing inodes. This was caught with xfstests. - fix another failing xfstest case in which switching a file from ordered_write to journaled data via set_flags caused a deadlock" * tag 'gfs2-4.15.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: gfs2: Allow gfs2_xattr_set to be called with the glock held gfs2: Add support for statx inode flags gfs2: Fix and clean up {GET,SET}FLAGS ioctl gfs2: Fix a harmless typo gfs2: Fix xattr fsync GFS2: Take inode off order_write list when setting jdata flag GFS2: flush the log and all pages for jdata as we do for WB_SYNC_ALL gfs2: Implement SEEK_HOLE / SEEK_DATA via iomap GFS2: Switch fiemap implementation to use iomap GFS2: Implement iomap for block_map GFS2: Make height info part of metapath gfs2: Always update inode ctime in set_acl gfs2: Support negative atimes gfs2: Update ctime in setflags ioctl gfs2: Clarify gfs2_block_map
-rw-r--r--fs/gfs2/Kconfig1
-rw-r--r--fs/gfs2/acl.c1
-rw-r--r--fs/gfs2/bmap.c322
-rw-r--r--fs/gfs2/bmap.h4
-rw-r--r--fs/gfs2/file.c124
-rw-r--r--fs/gfs2/inode.c89
-rw-r--r--fs/gfs2/inode.h2
-rw-r--r--fs/gfs2/super.c5
-rw-r--r--fs/gfs2/trace_gfs2.h65
-rw-r--r--fs/gfs2/trans.c2
-rw-r--r--fs/gfs2/xattr.c63
-rw-r--r--include/linux/iomap.h3
12 files changed, 471 insertions, 210 deletions
diff --git a/fs/gfs2/Kconfig b/fs/gfs2/Kconfig
index 90c6a8faaecb..43c827a7cce5 100644
--- a/fs/gfs2/Kconfig
+++ b/fs/gfs2/Kconfig
@@ -4,6 +4,7 @@ config GFS2_FS
4 select FS_POSIX_ACL 4 select FS_POSIX_ACL
5 select CRC32 5 select CRC32
6 select QUOTACTL 6 select QUOTACTL
7 select FS_IOMAP
7 help 8 help
8 A cluster filesystem. 9 A cluster filesystem.
9 10
diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c
index 9d5eecb123de..776717f1eeea 100644
--- a/fs/gfs2/acl.c
+++ b/fs/gfs2/acl.c
@@ -141,6 +141,7 @@ int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
141 141
142 ret = __gfs2_set_acl(inode, acl, type); 142 ret = __gfs2_set_acl(inode, acl, type);
143 if (!ret && mode != inode->i_mode) { 143 if (!ret && mode != inode->i_mode) {
144 inode->i_ctime = current_time(inode);
144 inode->i_mode = mode; 145 inode->i_mode = mode;
145 mark_inode_dirty(inode); 146 mark_inode_dirty(inode);
146 } 147 }
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 3dd0cceefa43..d5f0d96169c5 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -13,6 +13,7 @@
13#include <linux/blkdev.h> 13#include <linux/blkdev.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/crc32.h> 15#include <linux/crc32.h>
16#include <linux/iomap.h>
16 17
17#include "gfs2.h" 18#include "gfs2.h"
18#include "incore.h" 19#include "incore.h"
@@ -36,6 +37,8 @@
36struct metapath { 37struct metapath {
37 struct buffer_head *mp_bh[GFS2_MAX_META_HEIGHT]; 38 struct buffer_head *mp_bh[GFS2_MAX_META_HEIGHT];
38 __u16 mp_list[GFS2_MAX_META_HEIGHT]; 39 __u16 mp_list[GFS2_MAX_META_HEIGHT];
40 int mp_fheight; /* find_metapath height */
41 int mp_aheight; /* actual height (lookup height) */
39}; 42};
40 43
41/** 44/**
@@ -235,9 +238,9 @@ static void find_metapath(const struct gfs2_sbd *sdp, u64 block,
235{ 238{
236 unsigned int i; 239 unsigned int i;
237 240
241 mp->mp_fheight = height;
238 for (i = height; i--;) 242 for (i = height; i--;)
239 mp->mp_list[i] = do_div(block, sdp->sd_inptrs); 243 mp->mp_list[i] = do_div(block, sdp->sd_inptrs);
240
241} 244}
242 245
243static inline unsigned int metapath_branch_start(const struct metapath *mp) 246static inline unsigned int metapath_branch_start(const struct metapath *mp)
@@ -248,7 +251,7 @@ static inline unsigned int metapath_branch_start(const struct metapath *mp)
248} 251}
249 252
250/** 253/**
251 * metaptr1 - Return the first possible metadata pointer in a metaath buffer 254 * metaptr1 - Return the first possible metadata pointer in a metapath buffer
252 * @height: The metadata height (0 = dinode) 255 * @height: The metadata height (0 = dinode)
253 * @mp: The metapath 256 * @mp: The metapath
254 */ 257 */
@@ -345,10 +348,13 @@ static int lookup_metapath(struct gfs2_inode *ip, struct metapath *mp)
345 for (x = 0; x < end_of_metadata; x++) { 348 for (x = 0; x < end_of_metadata; x++) {
346 ret = lookup_mp_height(ip, mp, x); 349 ret = lookup_mp_height(ip, mp, x);
347 if (ret) 350 if (ret)
348 return ret; 351 goto out;
349 } 352 }
350 353
351 return ip->i_height; 354 ret = ip->i_height;
355out:
356 mp->mp_aheight = ret;
357 return ret;
352} 358}
353 359
354/** 360/**
@@ -480,10 +486,11 @@ static inline unsigned int hptrs(struct gfs2_sbd *sdp, const unsigned int hgt)
480 * @inode: The GFS2 inode 486 * @inode: The GFS2 inode
481 * @lblock: The logical starting block of the extent 487 * @lblock: The logical starting block of the extent
482 * @bh_map: This is used to return the mapping details 488 * @bh_map: This is used to return the mapping details
483 * @mp: The metapath 489 * @zero_new: True if newly allocated blocks should be zeroed
484 * @sheight: The starting height (i.e. whats already mapped) 490 * @mp: The metapath, with proper height information calculated
485 * @height: The height to build to
486 * @maxlen: The max number of data blocks to alloc 491 * @maxlen: The max number of data blocks to alloc
492 * @dblock: Pointer to return the resulting new block
493 * @dblks: Pointer to return the number of blocks allocated
487 * 494 *
488 * In this routine we may have to alloc: 495 * In this routine we may have to alloc:
489 * i) Indirect blocks to grow the metadata tree height 496 * i) Indirect blocks to grow the metadata tree height
@@ -499,63 +506,63 @@ static inline unsigned int hptrs(struct gfs2_sbd *sdp, const unsigned int hgt)
499 * Returns: errno on error 506 * Returns: errno on error
500 */ 507 */
501 508
502static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, 509static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap,
503 struct buffer_head *bh_map, struct metapath *mp, 510 unsigned flags, struct metapath *mp)
504 const unsigned int sheight,
505 const unsigned int height,
506 const size_t maxlen)
507{ 511{
508 struct gfs2_inode *ip = GFS2_I(inode); 512 struct gfs2_inode *ip = GFS2_I(inode);
509 struct gfs2_sbd *sdp = GFS2_SB(inode); 513 struct gfs2_sbd *sdp = GFS2_SB(inode);
510 struct super_block *sb = sdp->sd_vfs; 514 struct super_block *sb = sdp->sd_vfs;
511 struct buffer_head *dibh = mp->mp_bh[0]; 515 struct buffer_head *dibh = mp->mp_bh[0];
512 u64 bn, dblock = 0; 516 u64 bn;
513 unsigned n, i, blks, alloced = 0, iblks = 0, branch_start = 0; 517 unsigned n, i, blks, alloced = 0, iblks = 0, branch_start = 0;
514 unsigned dblks = 0; 518 unsigned dblks = 0;
515 unsigned ptrs_per_blk; 519 unsigned ptrs_per_blk;
516 const unsigned end_of_metadata = height - 1; 520 const unsigned end_of_metadata = mp->mp_fheight - 1;
517 int ret; 521 int ret;
518 int eob = 0;
519 enum alloc_state state; 522 enum alloc_state state;
520 __be64 *ptr; 523 __be64 *ptr;
521 __be64 zero_bn = 0; 524 __be64 zero_bn = 0;
525 size_t maxlen = iomap->length >> inode->i_blkbits;
522 526
523 BUG_ON(sheight < 1); 527 BUG_ON(mp->mp_aheight < 1);
524 BUG_ON(dibh == NULL); 528 BUG_ON(dibh == NULL);
525 529
526 gfs2_trans_add_meta(ip->i_gl, dibh); 530 gfs2_trans_add_meta(ip->i_gl, dibh);
527 531
528 if (height == sheight) { 532 if (mp->mp_fheight == mp->mp_aheight) {
529 struct buffer_head *bh; 533 struct buffer_head *bh;
534 int eob;
535
530 /* Bottom indirect block exists, find unalloced extent size */ 536 /* Bottom indirect block exists, find unalloced extent size */
531 ptr = metapointer(end_of_metadata, mp); 537 ptr = metapointer(end_of_metadata, mp);
532 bh = mp->mp_bh[end_of_metadata]; 538 bh = mp->mp_bh[end_of_metadata];
533 dblks = gfs2_extent_length(bh->b_data, bh->b_size, ptr, maxlen, 539 dblks = gfs2_extent_length(bh->b_data, bh->b_size, ptr,
534 &eob); 540 maxlen, &eob);
535 BUG_ON(dblks < 1); 541 BUG_ON(dblks < 1);
536 state = ALLOC_DATA; 542 state = ALLOC_DATA;
537 } else { 543 } else {
538 /* Need to allocate indirect blocks */ 544 /* Need to allocate indirect blocks */
539 ptrs_per_blk = height > 1 ? sdp->sd_inptrs : sdp->sd_diptrs; 545 ptrs_per_blk = mp->mp_fheight > 1 ? sdp->sd_inptrs :
546 sdp->sd_diptrs;
540 dblks = min(maxlen, (size_t)(ptrs_per_blk - 547 dblks = min(maxlen, (size_t)(ptrs_per_blk -
541 mp->mp_list[end_of_metadata])); 548 mp->mp_list[end_of_metadata]));
542 if (height == ip->i_height) { 549 if (mp->mp_fheight == ip->i_height) {
543 /* Writing into existing tree, extend tree down */ 550 /* Writing into existing tree, extend tree down */
544 iblks = height - sheight; 551 iblks = mp->mp_fheight - mp->mp_aheight;
545 state = ALLOC_GROW_DEPTH; 552 state = ALLOC_GROW_DEPTH;
546 } else { 553 } else {
547 /* Building up tree height */ 554 /* Building up tree height */
548 state = ALLOC_GROW_HEIGHT; 555 state = ALLOC_GROW_HEIGHT;
549 iblks = height - ip->i_height; 556 iblks = mp->mp_fheight - ip->i_height;
550 branch_start = metapath_branch_start(mp); 557 branch_start = metapath_branch_start(mp);
551 iblks += (height - branch_start); 558 iblks += (mp->mp_fheight - branch_start);
552 } 559 }
553 } 560 }
554 561
555 /* start of the second part of the function (state machine) */ 562 /* start of the second part of the function (state machine) */
556 563
557 blks = dblks + iblks; 564 blks = dblks + iblks;
558 i = sheight; 565 i = mp->mp_aheight;
559 do { 566 do {
560 int error; 567 int error;
561 n = blks - alloced; 568 n = blks - alloced;
@@ -573,9 +580,10 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,
573 sizeof(struct gfs2_dinode)); 580 sizeof(struct gfs2_dinode));
574 zero_bn = *ptr; 581 zero_bn = *ptr;
575 } 582 }
576 for (; i - 1 < height - ip->i_height && n > 0; i++, n--) 583 for (; i - 1 < mp->mp_fheight - ip->i_height && n > 0;
584 i++, n--)
577 gfs2_indirect_init(mp, ip->i_gl, i, 0, bn++); 585 gfs2_indirect_init(mp, ip->i_gl, i, 0, bn++);
578 if (i - 1 == height - ip->i_height) { 586 if (i - 1 == mp->mp_fheight - ip->i_height) {
579 i--; 587 i--;
580 gfs2_buffer_copy_tail(mp->mp_bh[i], 588 gfs2_buffer_copy_tail(mp->mp_bh[i],
581 sizeof(struct gfs2_meta_header), 589 sizeof(struct gfs2_meta_header),
@@ -587,7 +595,7 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,
587 sizeof(struct gfs2_meta_header)); 595 sizeof(struct gfs2_meta_header));
588 *ptr = zero_bn; 596 *ptr = zero_bn;
589 state = ALLOC_GROW_DEPTH; 597 state = ALLOC_GROW_DEPTH;
590 for(i = branch_start; i < height; i++) { 598 for(i = branch_start; i < mp->mp_fheight; i++) {
591 if (mp->mp_bh[i] == NULL) 599 if (mp->mp_bh[i] == NULL)
592 break; 600 break;
593 brelse(mp->mp_bh[i]); 601 brelse(mp->mp_bh[i]);
@@ -599,12 +607,12 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,
599 break; 607 break;
600 /* Branching from existing tree */ 608 /* Branching from existing tree */
601 case ALLOC_GROW_DEPTH: 609 case ALLOC_GROW_DEPTH:
602 if (i > 1 && i < height) 610 if (i > 1 && i < mp->mp_fheight)
603 gfs2_trans_add_meta(ip->i_gl, mp->mp_bh[i-1]); 611 gfs2_trans_add_meta(ip->i_gl, mp->mp_bh[i-1]);
604 for (; i < height && n > 0; i++, n--) 612 for (; i < mp->mp_fheight && n > 0; i++, n--)
605 gfs2_indirect_init(mp, ip->i_gl, i, 613 gfs2_indirect_init(mp, ip->i_gl, i,
606 mp->mp_list[i-1], bn++); 614 mp->mp_list[i-1], bn++);
607 if (i == height) 615 if (i == mp->mp_fheight)
608 state = ALLOC_DATA; 616 state = ALLOC_DATA;
609 if (n == 0) 617 if (n == 0)
610 break; 618 break;
@@ -615,119 +623,269 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,
615 gfs2_trans_add_meta(ip->i_gl, mp->mp_bh[end_of_metadata]); 623 gfs2_trans_add_meta(ip->i_gl, mp->mp_bh[end_of_metadata]);
616 dblks = n; 624 dblks = n;
617 ptr = metapointer(end_of_metadata, mp); 625 ptr = metapointer(end_of_metadata, mp);
618 dblock = bn; 626 iomap->addr = bn << inode->i_blkbits;
627 iomap->flags |= IOMAP_F_NEW;
619 while (n-- > 0) 628 while (n-- > 0)
620 *ptr++ = cpu_to_be64(bn++); 629 *ptr++ = cpu_to_be64(bn++);
621 if (buffer_zeronew(bh_map)) { 630 if (flags & IOMAP_ZERO) {
622 ret = sb_issue_zeroout(sb, dblock, dblks, 631 ret = sb_issue_zeroout(sb, iomap->addr >> inode->i_blkbits,
623 GFP_NOFS); 632 dblks, GFP_NOFS);
624 if (ret) { 633 if (ret) {
625 fs_err(sdp, 634 fs_err(sdp,
626 "Failed to zero data buffers\n"); 635 "Failed to zero data buffers\n");
627 clear_buffer_zeronew(bh_map); 636 flags &= ~IOMAP_ZERO;
628 } 637 }
629 } 638 }
630 break; 639 break;
631 } 640 }
632 } while ((state != ALLOC_DATA) || !dblock); 641 } while (iomap->addr == IOMAP_NULL_ADDR);
633 642
634 ip->i_height = height; 643 iomap->length = (u64)dblks << inode->i_blkbits;
644 ip->i_height = mp->mp_fheight;
635 gfs2_add_inode_blocks(&ip->i_inode, alloced); 645 gfs2_add_inode_blocks(&ip->i_inode, alloced);
636 gfs2_dinode_out(ip, mp->mp_bh[0]->b_data); 646 gfs2_dinode_out(ip, mp->mp_bh[0]->b_data);
637 map_bh(bh_map, inode->i_sb, dblock);
638 bh_map->b_size = dblks << inode->i_blkbits;
639 set_buffer_new(bh_map);
640 return 0; 647 return 0;
641} 648}
642 649
643/** 650/**
644 * gfs2_block_map - Map a block from an inode to a disk block 651 * hole_size - figure out the size of a hole
645 * @inode: The inode 652 * @inode: The inode
646 * @lblock: The logical block number 653 * @lblock: The logical starting block number
647 * @bh_map: The bh to be mapped 654 * @mp: The metapath
648 * @create: True if its ok to alloc blocks to satify the request
649 * 655 *
650 * Sets buffer_mapped() if successful, sets buffer_boundary() if a 656 * Returns: The hole size in bytes
651 * read of metadata will be required before the next block can be
652 * mapped. Sets buffer_new() if new blocks were allocated.
653 * 657 *
654 * Returns: errno
655 */ 658 */
659static u64 hole_size(struct inode *inode, sector_t lblock, struct metapath *mp)
660{
661 struct gfs2_inode *ip = GFS2_I(inode);
662 struct gfs2_sbd *sdp = GFS2_SB(inode);
663 struct metapath mp_eof;
664 u64 factor = 1;
665 int hgt;
666 u64 holesz = 0;
667 const __be64 *first, *end, *ptr;
668 const struct buffer_head *bh;
669 u64 lblock_stop = (i_size_read(inode) - 1) >> inode->i_blkbits;
670 int zeroptrs;
671 bool done = false;
672
673 /* Get another metapath, to the very last byte */
674 find_metapath(sdp, lblock_stop, &mp_eof, ip->i_height);
675 for (hgt = ip->i_height - 1; hgt >= 0 && !done; hgt--) {
676 bh = mp->mp_bh[hgt];
677 if (bh) {
678 zeroptrs = 0;
679 first = metapointer(hgt, mp);
680 end = (const __be64 *)(bh->b_data + bh->b_size);
681
682 for (ptr = first; ptr < end; ptr++) {
683 if (*ptr) {
684 done = true;
685 break;
686 } else {
687 zeroptrs++;
688 }
689 }
690 } else {
691 zeroptrs = sdp->sd_inptrs;
692 }
693 if (factor * zeroptrs >= lblock_stop - lblock + 1) {
694 holesz = lblock_stop - lblock + 1;
695 break;
696 }
697 holesz += factor * zeroptrs;
656 698
657int gfs2_block_map(struct inode *inode, sector_t lblock, 699 factor *= sdp->sd_inptrs;
658 struct buffer_head *bh_map, int create) 700 if (hgt && (mp->mp_list[hgt - 1] < mp_eof.mp_list[hgt - 1]))
701 (mp->mp_list[hgt - 1])++;
702 }
703 return holesz << inode->i_blkbits;
704}
705
706static void gfs2_stuffed_iomap(struct inode *inode, struct iomap *iomap)
707{
708 struct gfs2_inode *ip = GFS2_I(inode);
709
710 iomap->addr = (ip->i_no_addr << inode->i_blkbits) +
711 sizeof(struct gfs2_dinode);
712 iomap->offset = 0;
713 iomap->length = i_size_read(inode);
714 iomap->type = IOMAP_MAPPED;
715 iomap->flags = IOMAP_F_DATA_INLINE;
716}
717
718/**
719 * gfs2_iomap_begin - Map blocks from an inode to disk blocks
720 * @inode: The inode
721 * @pos: Starting position in bytes
722 * @length: Length to map, in bytes
723 * @flags: iomap flags
724 * @iomap: The iomap structure
725 *
726 * Returns: errno
727 */
728int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
729 unsigned flags, struct iomap *iomap)
659{ 730{
660 struct gfs2_inode *ip = GFS2_I(inode); 731 struct gfs2_inode *ip = GFS2_I(inode);
661 struct gfs2_sbd *sdp = GFS2_SB(inode); 732 struct gfs2_sbd *sdp = GFS2_SB(inode);
662 unsigned int bsize = sdp->sd_sb.sb_bsize; 733 struct metapath mp = { .mp_aheight = 1, };
663 const size_t maxlen = bh_map->b_size >> inode->i_blkbits; 734 unsigned int factor = sdp->sd_sb.sb_bsize;
664 const u64 *arr = sdp->sd_heightsize; 735 const u64 *arr = sdp->sd_heightsize;
665 __be64 *ptr; 736 __be64 *ptr;
666 u64 size; 737 sector_t lblock;
667 struct metapath mp; 738 sector_t lend;
668 int ret; 739 int ret;
669 int eob; 740 int eob;
670 unsigned int len; 741 unsigned int len;
671 struct buffer_head *bh; 742 struct buffer_head *bh;
672 u8 height; 743 u8 height;
673 744
674 BUG_ON(maxlen == 0); 745 trace_gfs2_iomap_start(ip, pos, length, flags);
746 if (!length) {
747 ret = -EINVAL;
748 goto out;
749 }
675 750
676 memset(&mp, 0, sizeof(mp)); 751 if ((flags & IOMAP_REPORT) && gfs2_is_stuffed(ip)) {
677 bmap_lock(ip, create); 752 gfs2_stuffed_iomap(inode, iomap);
678 clear_buffer_mapped(bh_map); 753 if (pos >= iomap->length)
679 clear_buffer_new(bh_map); 754 return -ENOENT;
680 clear_buffer_boundary(bh_map); 755 ret = 0;
681 trace_gfs2_bmap(ip, bh_map, lblock, create, 1); 756 goto out;
757 }
758
759 lblock = pos >> inode->i_blkbits;
760 lend = (pos + length + sdp->sd_sb.sb_bsize - 1) >> inode->i_blkbits;
761
762 iomap->offset = lblock << inode->i_blkbits;
763 iomap->addr = IOMAP_NULL_ADDR;
764 iomap->type = IOMAP_HOLE;
765 iomap->length = (u64)(lend - lblock) << inode->i_blkbits;
766 iomap->flags = IOMAP_F_MERGED;
767 bmap_lock(ip, 0);
768
769 /*
770 * Directory data blocks have a struct gfs2_meta_header header, so the
771 * remaining size is smaller than the filesystem block size. Logical
772 * block numbers for directories are in units of this remaining size!
773 */
682 if (gfs2_is_dir(ip)) { 774 if (gfs2_is_dir(ip)) {
683 bsize = sdp->sd_jbsize; 775 factor = sdp->sd_jbsize;
684 arr = sdp->sd_jheightsize; 776 arr = sdp->sd_jheightsize;
685 } 777 }
686 778
687 ret = gfs2_meta_inode_buffer(ip, &mp.mp_bh[0]); 779 ret = gfs2_meta_inode_buffer(ip, &mp.mp_bh[0]);
688 if (ret) 780 if (ret)
689 goto out; 781 goto out_release;
690 782
691 height = ip->i_height; 783 height = ip->i_height;
692 size = (lblock + 1) * bsize; 784 while ((lblock + 1) * factor > arr[height])
693 while (size > arr[height])
694 height++; 785 height++;
695 find_metapath(sdp, lblock, &mp, height); 786 find_metapath(sdp, lblock, &mp, height);
696 ret = 1;
697 if (height > ip->i_height || gfs2_is_stuffed(ip)) 787 if (height > ip->i_height || gfs2_is_stuffed(ip))
698 goto do_alloc; 788 goto do_alloc;
789
699 ret = lookup_metapath(ip, &mp); 790 ret = lookup_metapath(ip, &mp);
700 if (ret < 0) 791 if (ret < 0)
701 goto out; 792 goto out_release;
702 if (ret != ip->i_height) 793
794 if (mp.mp_aheight != ip->i_height)
703 goto do_alloc; 795 goto do_alloc;
796
704 ptr = metapointer(ip->i_height - 1, &mp); 797 ptr = metapointer(ip->i_height - 1, &mp);
705 if (*ptr == 0) 798 if (*ptr == 0)
706 goto do_alloc; 799 goto do_alloc;
707 map_bh(bh_map, inode->i_sb, be64_to_cpu(*ptr)); 800
801 iomap->type = IOMAP_MAPPED;
802 iomap->addr = be64_to_cpu(*ptr) << inode->i_blkbits;
803
708 bh = mp.mp_bh[ip->i_height - 1]; 804 bh = mp.mp_bh[ip->i_height - 1];
709 len = gfs2_extent_length(bh->b_data, bh->b_size, ptr, maxlen, &eob); 805 len = gfs2_extent_length(bh->b_data, bh->b_size, ptr, lend - lblock, &eob);
710 bh_map->b_size = (len << inode->i_blkbits);
711 if (eob) 806 if (eob)
712 set_buffer_boundary(bh_map); 807 iomap->flags |= IOMAP_F_BOUNDARY;
808 iomap->length = (u64)len << inode->i_blkbits;
809
713 ret = 0; 810 ret = 0;
714out: 811
812out_release:
715 release_metapath(&mp); 813 release_metapath(&mp);
716 trace_gfs2_bmap(ip, bh_map, lblock, create, ret); 814 bmap_unlock(ip, 0);
717 bmap_unlock(ip, create); 815out:
816 trace_gfs2_iomap_end(ip, iomap, ret);
718 return ret; 817 return ret;
719 818
720do_alloc: 819do_alloc:
721 /* All allocations are done here, firstly check create flag */ 820 if (!(flags & IOMAP_WRITE)) {
722 if (!create) { 821 if (pos >= i_size_read(inode)) {
723 BUG_ON(gfs2_is_stuffed(ip)); 822 ret = -ENOENT;
823 goto out_release;
824 }
724 ret = 0; 825 ret = 0;
826 iomap->length = hole_size(inode, lblock, &mp);
827 goto out_release;
828 }
829
830 ret = gfs2_iomap_alloc(inode, iomap, flags, &mp);
831 goto out_release;
832}
833
834/**
835 * gfs2_block_map - Map a block from an inode to a disk block
836 * @inode: The inode
837 * @lblock: The logical block number
838 * @bh_map: The bh to be mapped
839 * @create: True if its ok to alloc blocks to satify the request
840 *
841 * Sets buffer_mapped() if successful, sets buffer_boundary() if a
842 * read of metadata will be required before the next block can be
843 * mapped. Sets buffer_new() if new blocks were allocated.
844 *
845 * Returns: errno
846 */
847
848int gfs2_block_map(struct inode *inode, sector_t lblock,
849 struct buffer_head *bh_map, int create)
850{
851 struct gfs2_inode *ip = GFS2_I(inode);
852 struct iomap iomap;
853 int ret, flags = 0;
854
855 clear_buffer_mapped(bh_map);
856 clear_buffer_new(bh_map);
857 clear_buffer_boundary(bh_map);
858 trace_gfs2_bmap(ip, bh_map, lblock, create, 1);
859
860 if (create)
861 flags |= IOMAP_WRITE;
862 if (buffer_zeronew(bh_map))
863 flags |= IOMAP_ZERO;
864 ret = gfs2_iomap_begin(inode, (loff_t)lblock << inode->i_blkbits,
865 bh_map->b_size, flags, &iomap);
866 if (ret) {
867 if (!create && ret == -ENOENT) {
868 /* Return unmapped buffer beyond the end of file. */
869 ret = 0;
870 }
725 goto out; 871 goto out;
726 } 872 }
727 873
728 /* At this point ret is the tree depth of already allocated blocks */ 874 if (iomap.length > bh_map->b_size) {
729 ret = gfs2_bmap_alloc(inode, lblock, bh_map, &mp, ret, height, maxlen); 875 iomap.length = bh_map->b_size;
730 goto out; 876 iomap.flags &= ~IOMAP_F_BOUNDARY;
877 }
878 if (iomap.addr != IOMAP_NULL_ADDR)
879 map_bh(bh_map, inode->i_sb, iomap.addr >> inode->i_blkbits);
880 bh_map->b_size = iomap.length;
881 if (iomap.flags & IOMAP_F_BOUNDARY)
882 set_buffer_boundary(bh_map);
883 if (iomap.flags & IOMAP_F_NEW)
884 set_buffer_new(bh_map);
885
886out:
887 trace_gfs2_bmap(ip, bh_map, lblock, create, ret);
888 return ret;
731} 889}
732 890
733/* 891/*
diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h
index 81ded5e2aaa2..443cc182cf18 100644
--- a/fs/gfs2/bmap.h
+++ b/fs/gfs2/bmap.h
@@ -10,6 +10,8 @@
10#ifndef __BMAP_DOT_H__ 10#ifndef __BMAP_DOT_H__
11#define __BMAP_DOT_H__ 11#define __BMAP_DOT_H__
12 12
13#include <linux/iomap.h>
14
13#include "inode.h" 15#include "inode.h"
14 16
15struct inode; 17struct inode;
@@ -47,6 +49,8 @@ static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip,
47extern int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page); 49extern int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page);
48extern int gfs2_block_map(struct inode *inode, sector_t lblock, 50extern int gfs2_block_map(struct inode *inode, sector_t lblock,
49 struct buffer_head *bh, int create); 51 struct buffer_head *bh, int create);
52extern int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
53 unsigned flags, struct iomap *iomap);
50extern int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, 54extern int gfs2_extent_map(struct inode *inode, u64 lblock, int *new,
51 u64 *dblock, unsigned *extlen); 55 u64 *dblock, unsigned *extlen);
52extern int gfs2_setattr_size(struct inode *inode, u64 size); 56extern int gfs2_setattr_size(struct inode *inode, u64 size);
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
index 33a0cb5701a3..58705ef8643a 100644
--- a/fs/gfs2/file.c
+++ b/fs/gfs2/file.c
@@ -60,9 +60,7 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int whence)
60 loff_t error; 60 loff_t error;
61 61
62 switch (whence) { 62 switch (whence) {
63 case SEEK_END: /* These reference inode->i_size */ 63 case SEEK_END:
64 case SEEK_DATA:
65 case SEEK_HOLE:
66 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, 64 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY,
67 &i_gh); 65 &i_gh);
68 if (!error) { 66 if (!error) {
@@ -70,8 +68,21 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int whence)
70 gfs2_glock_dq_uninit(&i_gh); 68 gfs2_glock_dq_uninit(&i_gh);
71 } 69 }
72 break; 70 break;
71
72 case SEEK_DATA:
73 error = gfs2_seek_data(file, offset);
74 break;
75
76 case SEEK_HOLE:
77 error = gfs2_seek_hole(file, offset);
78 break;
79
73 case SEEK_CUR: 80 case SEEK_CUR:
74 case SEEK_SET: 81 case SEEK_SET:
82 /*
83 * These don't reference inode->i_size and don't depend on the
84 * block mapping, so we don't need the glock.
85 */
75 error = generic_file_llseek(file, offset, whence); 86 error = generic_file_llseek(file, offset, whence);
76 break; 87 break;
77 default: 88 default:
@@ -108,45 +119,22 @@ static int gfs2_readdir(struct file *file, struct dir_context *ctx)
108} 119}
109 120
110/** 121/**
111 * fsflags_cvt 122 * fsflag_gfs2flag
112 * @table: A table of 32 u32 flags
113 * @val: a 32 bit value to convert
114 *
115 * This function can be used to convert between fsflags values and
116 * GFS2's own flags values.
117 * 123 *
118 * Returns: the converted flags 124 * The FS_JOURNAL_DATA_FL flag maps to GFS2_DIF_INHERIT_JDATA for directories,
125 * and to GFS2_DIF_JDATA for non-directories.
119 */ 126 */
120static u32 fsflags_cvt(const u32 *table, u32 val) 127static struct {
121{ 128 u32 fsflag;
122 u32 res = 0; 129 u32 gfsflag;
123 while(val) { 130} fsflag_gfs2flag[] = {
124 if (val & 1) 131 {FS_SYNC_FL, GFS2_DIF_SYNC},
125 res |= *table; 132 {FS_IMMUTABLE_FL, GFS2_DIF_IMMUTABLE},
126 table++; 133 {FS_APPEND_FL, GFS2_DIF_APPENDONLY},
127 val >>= 1; 134 {FS_NOATIME_FL, GFS2_DIF_NOATIME},
128 } 135 {FS_INDEX_FL, GFS2_DIF_EXHASH},
129 return res; 136 {FS_TOPDIR_FL, GFS2_DIF_TOPDIR},
130} 137 {FS_JOURNAL_DATA_FL, GFS2_DIF_JDATA | GFS2_DIF_INHERIT_JDATA},
131
132static const u32 fsflags_to_gfs2[32] = {
133 [3] = GFS2_DIF_SYNC,
134 [4] = GFS2_DIF_IMMUTABLE,
135 [5] = GFS2_DIF_APPENDONLY,
136 [7] = GFS2_DIF_NOATIME,
137 [12] = GFS2_DIF_EXHASH,
138 [14] = GFS2_DIF_INHERIT_JDATA,
139 [17] = GFS2_DIF_TOPDIR,
140};
141
142static const u32 gfs2_to_fsflags[32] = {
143 [gfs2fl_Sync] = FS_SYNC_FL,
144 [gfs2fl_Immutable] = FS_IMMUTABLE_FL,
145 [gfs2fl_AppendOnly] = FS_APPEND_FL,
146 [gfs2fl_NoAtime] = FS_NOATIME_FL,
147 [gfs2fl_ExHash] = FS_INDEX_FL,
148 [gfs2fl_TopLevel] = FS_TOPDIR_FL,
149 [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
150}; 138};
151 139
152static int gfs2_get_flags(struct file *filp, u32 __user *ptr) 140static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
@@ -154,17 +142,23 @@ static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
154 struct inode *inode = file_inode(filp); 142 struct inode *inode = file_inode(filp);
155 struct gfs2_inode *ip = GFS2_I(inode); 143 struct gfs2_inode *ip = GFS2_I(inode);
156 struct gfs2_holder gh; 144 struct gfs2_holder gh;
157 int error; 145 int i, error;
158 u32 fsflags; 146 u32 gfsflags, fsflags = 0;
159 147
160 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &gh); 148 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
161 error = gfs2_glock_nq(&gh); 149 error = gfs2_glock_nq(&gh);
162 if (error) 150 if (error)
163 goto out_uninit; 151 goto out_uninit;
164 152
165 fsflags = fsflags_cvt(gfs2_to_fsflags, ip->i_diskflags); 153 gfsflags = ip->i_diskflags;
166 if (!S_ISDIR(inode->i_mode) && ip->i_diskflags & GFS2_DIF_JDATA) 154 if (S_ISDIR(inode->i_mode))
167 fsflags |= FS_JOURNAL_DATA_FL; 155 gfsflags &= ~GFS2_DIF_JDATA;
156 else
157 gfsflags &= ~GFS2_DIF_INHERIT_JDATA;
158 for (i = 0; i < ARRAY_SIZE(fsflag_gfs2flag); i++)
159 if (gfsflags & fsflag_gfs2flag[i].gfsflag)
160 fsflags |= fsflag_gfs2flag[i].fsflag;
161
168 if (put_user(fsflags, ptr)) 162 if (put_user(fsflags, ptr))
169 error = -EFAULT; 163 error = -EFAULT;
170 164
@@ -199,7 +193,6 @@ void gfs2_set_inode_flags(struct inode *inode)
199 GFS2_DIF_APPENDONLY| \ 193 GFS2_DIF_APPENDONLY| \
200 GFS2_DIF_NOATIME| \ 194 GFS2_DIF_NOATIME| \
201 GFS2_DIF_SYNC| \ 195 GFS2_DIF_SYNC| \
202 GFS2_DIF_SYSTEM| \
203 GFS2_DIF_TOPDIR| \ 196 GFS2_DIF_TOPDIR| \
204 GFS2_DIF_INHERIT_JDATA) 197 GFS2_DIF_INHERIT_JDATA)
205 198
@@ -238,10 +231,6 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
238 if ((new_flags ^ flags) == 0) 231 if ((new_flags ^ flags) == 0)
239 goto out; 232 goto out;
240 233
241 error = -EINVAL;
242 if ((new_flags ^ flags) & ~GFS2_FLAGS_USER_SET)
243 goto out;
244
245 error = -EPERM; 234 error = -EPERM;
246 if (IS_IMMUTABLE(inode) && (new_flags & GFS2_DIF_IMMUTABLE)) 235 if (IS_IMMUTABLE(inode) && (new_flags & GFS2_DIF_IMMUTABLE))
247 goto out; 236 goto out;
@@ -256,7 +245,7 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
256 goto out; 245 goto out;
257 } 246 }
258 if ((flags ^ new_flags) & GFS2_DIF_JDATA) { 247 if ((flags ^ new_flags) & GFS2_DIF_JDATA) {
259 if (flags & GFS2_DIF_JDATA) 248 if (new_flags & GFS2_DIF_JDATA)
260 gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH); 249 gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
261 error = filemap_fdatawrite(inode->i_mapping); 250 error = filemap_fdatawrite(inode->i_mapping);
262 if (error) 251 if (error)
@@ -264,6 +253,8 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
264 error = filemap_fdatawait(inode->i_mapping); 253 error = filemap_fdatawait(inode->i_mapping);
265 if (error) 254 if (error)
266 goto out; 255 goto out;
256 if (new_flags & GFS2_DIF_JDATA)
257 gfs2_ordered_del_inode(ip);
267 } 258 }
268 error = gfs2_trans_begin(sdp, RES_DINODE, 0); 259 error = gfs2_trans_begin(sdp, RES_DINODE, 0);
269 if (error) 260 if (error)
@@ -271,6 +262,7 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
271 error = gfs2_meta_inode_buffer(ip, &bh); 262 error = gfs2_meta_inode_buffer(ip, &bh);
272 if (error) 263 if (error)
273 goto out_trans_end; 264 goto out_trans_end;
265 inode->i_ctime = current_time(inode);
274 gfs2_trans_add_meta(ip->i_gl, bh); 266 gfs2_trans_add_meta(ip->i_gl, bh);
275 ip->i_diskflags = new_flags; 267 ip->i_diskflags = new_flags;
276 gfs2_dinode_out(ip, bh->b_data); 268 gfs2_dinode_out(ip, bh->b_data);
@@ -289,19 +281,33 @@ out_drop_write:
289static int gfs2_set_flags(struct file *filp, u32 __user *ptr) 281static int gfs2_set_flags(struct file *filp, u32 __user *ptr)
290{ 282{
291 struct inode *inode = file_inode(filp); 283 struct inode *inode = file_inode(filp);
292 u32 fsflags, gfsflags; 284 u32 fsflags, gfsflags = 0;
285 u32 mask;
286 int i;
293 287
294 if (get_user(fsflags, ptr)) 288 if (get_user(fsflags, ptr))
295 return -EFAULT; 289 return -EFAULT;
296 290
297 gfsflags = fsflags_cvt(fsflags_to_gfs2, fsflags); 291 for (i = 0; i < ARRAY_SIZE(fsflag_gfs2flag); i++) {
298 if (!S_ISDIR(inode->i_mode)) { 292 if (fsflags & fsflag_gfs2flag[i].fsflag) {
299 gfsflags &= ~GFS2_DIF_TOPDIR; 293 fsflags &= ~fsflag_gfs2flag[i].fsflag;
300 if (gfsflags & GFS2_DIF_INHERIT_JDATA) 294 gfsflags |= fsflag_gfs2flag[i].gfsflag;
301 gfsflags ^= (GFS2_DIF_JDATA | GFS2_DIF_INHERIT_JDATA); 295 }
302 return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_SYSTEM); 296 }
297 if (fsflags || gfsflags & ~GFS2_FLAGS_USER_SET)
298 return -EINVAL;
299
300 mask = GFS2_FLAGS_USER_SET;
301 if (S_ISDIR(inode->i_mode)) {
302 mask &= ~GFS2_DIF_JDATA;
303 } else {
304 /* The GFS2_DIF_TOPDIR flag is only valid for directories. */
305 if (gfsflags & GFS2_DIF_TOPDIR)
306 return -EINVAL;
307 mask &= ~(GFS2_DIF_TOPDIR | GFS2_DIF_INHERIT_JDATA);
303 } 308 }
304 return do_gfs2_set_flags(filp, gfsflags, ~(GFS2_DIF_SYSTEM | GFS2_DIF_JDATA)); 309
310 return do_gfs2_set_flags(filp, gfsflags, mask);
305} 311}
306 312
307static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 313static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 863749e29bf9..4e971b1c7f92 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -18,7 +18,7 @@
18#include <linux/posix_acl.h> 18#include <linux/posix_acl.h>
19#include <linux/gfs2_ondisk.h> 19#include <linux/gfs2_ondisk.h>
20#include <linux/crc32.h> 20#include <linux/crc32.h>
21#include <linux/fiemap.h> 21#include <linux/iomap.h>
22#include <linux/security.h> 22#include <linux/security.h>
23#include <linux/uaccess.h> 23#include <linux/uaccess.h>
24 24
@@ -189,7 +189,8 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
189 189
190 gfs2_set_iop(inode); 190 gfs2_set_iop(inode);
191 191
192 inode->i_atime.tv_sec = 0; 192 /* Lowest possible timestamp; will be overwritten in gfs2_dinode_in. */
193 inode->i_atime.tv_sec = 1LL << (8 * sizeof(inode->i_atime.tv_sec) - 1);
193 inode->i_atime.tv_nsec = 0; 194 inode->i_atime.tv_nsec = 0;
194 195
195 unlock_new_inode(inode); 196 unlock_new_inode(inode);
@@ -1986,6 +1987,7 @@ static int gfs2_getattr(const struct path *path, struct kstat *stat,
1986 struct inode *inode = d_inode(path->dentry); 1987 struct inode *inode = d_inode(path->dentry);
1987 struct gfs2_inode *ip = GFS2_I(inode); 1988 struct gfs2_inode *ip = GFS2_I(inode);
1988 struct gfs2_holder gh; 1989 struct gfs2_holder gh;
1990 u32 gfsflags;
1989 int error; 1991 int error;
1990 1992
1991 gfs2_holder_mark_uninitialized(&gh); 1993 gfs2_holder_mark_uninitialized(&gh);
@@ -1995,13 +1997,30 @@ static int gfs2_getattr(const struct path *path, struct kstat *stat,
1995 return error; 1997 return error;
1996 } 1998 }
1997 1999
2000 gfsflags = ip->i_diskflags;
2001 if (gfsflags & GFS2_DIF_APPENDONLY)
2002 stat->attributes |= STATX_ATTR_APPEND;
2003 if (gfsflags & GFS2_DIF_IMMUTABLE)
2004 stat->attributes |= STATX_ATTR_IMMUTABLE;
2005
2006 stat->attributes_mask |= (STATX_ATTR_APPEND |
2007 STATX_ATTR_COMPRESSED |
2008 STATX_ATTR_ENCRYPTED |
2009 STATX_ATTR_IMMUTABLE |
2010 STATX_ATTR_NODUMP);
2011
1998 generic_fillattr(inode, stat); 2012 generic_fillattr(inode, stat);
2013
1999 if (gfs2_holder_initialized(&gh)) 2014 if (gfs2_holder_initialized(&gh))
2000 gfs2_glock_dq_uninit(&gh); 2015 gfs2_glock_dq_uninit(&gh);
2001 2016
2002 return 0; 2017 return 0;
2003} 2018}
2004 2019
2020const struct iomap_ops gfs2_iomap_ops = {
2021 .iomap_begin = gfs2_iomap_begin,
2022};
2023
2005static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2024static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2006 u64 start, u64 len) 2025 u64 start, u64 len)
2007{ 2026{
@@ -2009,41 +2028,59 @@ static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2009 struct gfs2_holder gh; 2028 struct gfs2_holder gh;
2010 int ret; 2029 int ret;
2011 2030
2012 ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC); 2031 inode_lock_shared(inode);
2013 if (ret)
2014 return ret;
2015
2016 inode_lock(inode);
2017 2032
2018 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh); 2033 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
2019 if (ret) 2034 if (ret)
2020 goto out; 2035 goto out;
2021 2036
2022 if (gfs2_is_stuffed(ip)) { 2037 ret = iomap_fiemap(inode, fieinfo, start, len, &gfs2_iomap_ops);
2023 u64 phys = ip->i_no_addr << inode->i_blkbits;
2024 u64 size = i_size_read(inode);
2025 u32 flags = FIEMAP_EXTENT_LAST|FIEMAP_EXTENT_NOT_ALIGNED|
2026 FIEMAP_EXTENT_DATA_INLINE;
2027 phys += sizeof(struct gfs2_dinode);
2028 phys += start;
2029 if (start + len > size)
2030 len = size - start;
2031 if (start < size)
2032 ret = fiemap_fill_next_extent(fieinfo, start, phys,
2033 len, flags);
2034 if (ret == 1)
2035 ret = 0;
2036 } else {
2037 ret = __generic_block_fiemap(inode, fieinfo, start, len,
2038 gfs2_block_map);
2039 }
2040 2038
2041 gfs2_glock_dq_uninit(&gh); 2039 gfs2_glock_dq_uninit(&gh);
2040
2042out: 2041out:
2043 inode_unlock(inode); 2042 inode_unlock_shared(inode);
2044 return ret; 2043 return ret;
2045} 2044}
2046 2045
2046loff_t gfs2_seek_data(struct file *file, loff_t offset)
2047{
2048 struct inode *inode = file->f_mapping->host;
2049 struct gfs2_inode *ip = GFS2_I(inode);
2050 struct gfs2_holder gh;
2051 loff_t ret;
2052
2053 inode_lock_shared(inode);
2054 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
2055 if (!ret)
2056 ret = iomap_seek_data(inode, offset, &gfs2_iomap_ops);
2057 gfs2_glock_dq_uninit(&gh);
2058 inode_unlock_shared(inode);
2059
2060 if (ret < 0)
2061 return ret;
2062 return vfs_setpos(file, ret, inode->i_sb->s_maxbytes);
2063}
2064
2065loff_t gfs2_seek_hole(struct file *file, loff_t offset)
2066{
2067 struct inode *inode = file->f_mapping->host;
2068 struct gfs2_inode *ip = GFS2_I(inode);
2069 struct gfs2_holder gh;
2070 loff_t ret;
2071
2072 inode_lock_shared(inode);
2073 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
2074 if (!ret)
2075 ret = iomap_seek_hole(inode, offset, &gfs2_iomap_ops);
2076 gfs2_glock_dq_uninit(&gh);
2077 inode_unlock_shared(inode);
2078
2079 if (ret < 0)
2080 return ret;
2081 return vfs_setpos(file, ret, inode->i_sb->s_maxbytes);
2082}
2083
2047const struct inode_operations gfs2_file_iops = { 2084const struct inode_operations gfs2_file_iops = {
2048 .permission = gfs2_permission, 2085 .permission = gfs2_permission,
2049 .setattr = gfs2_setattr, 2086 .setattr = gfs2_setattr,
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index aace8ce34a18..b5b6341a4f5c 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -109,6 +109,8 @@ extern int gfs2_setattr_simple(struct inode *inode, struct iattr *attr);
109extern struct inode *gfs2_lookup_simple(struct inode *dip, const char *name); 109extern struct inode *gfs2_lookup_simple(struct inode *dip, const char *name);
110extern void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf); 110extern void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf);
111extern int gfs2_open_common(struct inode *inode, struct file *file); 111extern int gfs2_open_common(struct inode *inode, struct file *file);
112extern loff_t gfs2_seek_data(struct file *file, loff_t offset);
113extern loff_t gfs2_seek_hole(struct file *file, loff_t offset);
112 114
113extern const struct inode_operations gfs2_file_iops; 115extern const struct inode_operations gfs2_file_iops;
114extern const struct inode_operations gfs2_dir_iops; 116extern const struct inode_operations gfs2_dir_iops;
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 8e54f2e3a304..9cb5c9a97d69 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -754,14 +754,15 @@ static int gfs2_write_inode(struct inode *inode, struct writeback_control *wbc)
754 struct address_space *metamapping = gfs2_glock2aspace(ip->i_gl); 754 struct address_space *metamapping = gfs2_glock2aspace(ip->i_gl);
755 struct backing_dev_info *bdi = inode_to_bdi(metamapping->host); 755 struct backing_dev_info *bdi = inode_to_bdi(metamapping->host);
756 int ret = 0; 756 int ret = 0;
757 bool flush_all = (wbc->sync_mode == WB_SYNC_ALL || gfs2_is_jdata(ip));
757 758
758 if (wbc->sync_mode == WB_SYNC_ALL) 759 if (flush_all)
759 gfs2_log_flush(GFS2_SB(inode), ip->i_gl, NORMAL_FLUSH); 760 gfs2_log_flush(GFS2_SB(inode), ip->i_gl, NORMAL_FLUSH);
760 if (bdi->wb.dirty_exceeded) 761 if (bdi->wb.dirty_exceeded)
761 gfs2_ail1_flush(sdp, wbc); 762 gfs2_ail1_flush(sdp, wbc);
762 else 763 else
763 filemap_fdatawrite(metamapping); 764 filemap_fdatawrite(metamapping);
764 if (wbc->sync_mode == WB_SYNC_ALL) 765 if (flush_all)
765 ret = filemap_fdatawait(metamapping); 766 ret = filemap_fdatawait(metamapping);
766 if (ret) 767 if (ret)
767 mark_inode_dirty_sync(inode); 768 mark_inode_dirty_sync(inode);
diff --git a/fs/gfs2/trace_gfs2.h b/fs/gfs2/trace_gfs2.h
index 2f159265693b..f67a709589d3 100644
--- a/fs/gfs2/trace_gfs2.h
+++ b/fs/gfs2/trace_gfs2.h
@@ -13,6 +13,7 @@
13#include <linux/gfs2_ondisk.h> 13#include <linux/gfs2_ondisk.h>
14#include <linux/writeback.h> 14#include <linux/writeback.h>
15#include <linux/ktime.h> 15#include <linux/ktime.h>
16#include <linux/iomap.h>
16#include "incore.h" 17#include "incore.h"
17#include "glock.h" 18#include "glock.h"
18#include "rgrp.h" 19#include "rgrp.h"
@@ -470,6 +471,70 @@ TRACE_EVENT(gfs2_bmap,
470 __entry->errno) 471 __entry->errno)
471); 472);
472 473
474TRACE_EVENT(gfs2_iomap_start,
475
476 TP_PROTO(const struct gfs2_inode *ip, loff_t pos, ssize_t length,
477 u16 flags),
478
479 TP_ARGS(ip, pos, length, flags),
480
481 TP_STRUCT__entry(
482 __field( dev_t, dev )
483 __field( u64, inum )
484 __field( loff_t, pos )
485 __field( ssize_t, length )
486 __field( u16, flags )
487 ),
488
489 TP_fast_assign(
490 __entry->dev = ip->i_gl->gl_name.ln_sbd->sd_vfs->s_dev;
491 __entry->inum = ip->i_no_addr;
492 __entry->pos = pos;
493 __entry->length = length;
494 __entry->flags = flags;
495 ),
496
497 TP_printk("%u,%u bmap %llu iomap start %llu/%lu flags:%08x",
498 MAJOR(__entry->dev), MINOR(__entry->dev),
499 (unsigned long long)__entry->inum,
500 (unsigned long long)__entry->pos,
501 (unsigned long)__entry->length, (u16)__entry->flags)
502);
503
504TRACE_EVENT(gfs2_iomap_end,
505
506 TP_PROTO(const struct gfs2_inode *ip, struct iomap *iomap, int ret),
507
508 TP_ARGS(ip, iomap, ret),
509
510 TP_STRUCT__entry(
511 __field( dev_t, dev )
512 __field( u64, inum )
513 __field( loff_t, offset )
514 __field( ssize_t, length )
515 __field( u16, flags )
516 __field( u16, type )
517 __field( int, ret )
518 ),
519
520 TP_fast_assign(
521 __entry->dev = ip->i_gl->gl_name.ln_sbd->sd_vfs->s_dev;
522 __entry->inum = ip->i_no_addr;
523 __entry->offset = iomap->offset;
524 __entry->length = iomap->length;
525 __entry->flags = iomap->flags;
526 __entry->type = iomap->type;
527 __entry->ret = ret;
528 ),
529
530 TP_printk("%u,%u bmap %llu iomap end %llu/%lu ty:%d flags:%08x rc:%d",
531 MAJOR(__entry->dev), MINOR(__entry->dev),
532 (unsigned long long)__entry->inum,
533 (unsigned long long)__entry->offset,
534 (unsigned long)__entry->length, (u16)__entry->type,
535 (u16)__entry->flags, __entry->ret)
536);
537
473/* Keep track of blocks as they are allocated/freed */ 538/* Keep track of blocks as they are allocated/freed */
474TRACE_EVENT(gfs2_block_alloc, 539TRACE_EVENT(gfs2_block_alloc,
475 540
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index affef3c066e0..a85ca8b2c9ba 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -145,7 +145,7 @@ static struct gfs2_bufdata *gfs2_alloc_bufdata(struct gfs2_glock *gl,
145 * 145 *
146 * This is used in two distinct cases: 146 * This is used in two distinct cases:
147 * i) In ordered write mode 147 * i) In ordered write mode
148 * We put the data buffer on a list so that we can ensure that its 148 * We put the data buffer on a list so that we can ensure that it's
149 * synced to disk at the right time 149 * synced to disk at the right time
150 * ii) In journaled data mode 150 * ii) In journaled data mode
151 * We need to journal the data block in the same way as metadata in 151 * We need to journal the data block in the same way as metadata in
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c
index ea09e41dbb49..05de20954659 100644
--- a/fs/gfs2/xattr.c
+++ b/fs/gfs2/xattr.c
@@ -231,7 +231,6 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
231 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 231 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
232 struct gfs2_rgrpd *rgd; 232 struct gfs2_rgrpd *rgd;
233 struct gfs2_holder rg_gh; 233 struct gfs2_holder rg_gh;
234 struct buffer_head *dibh;
235 __be64 *dataptrs; 234 __be64 *dataptrs;
236 u64 bn = 0; 235 u64 bn = 0;
237 u64 bstart = 0; 236 u64 bstart = 0;
@@ -308,13 +307,8 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
308 ea->ea_num_ptrs = 0; 307 ea->ea_num_ptrs = 0;
309 } 308 }
310 309
311 error = gfs2_meta_inode_buffer(ip, &dibh); 310 ip->i_inode.i_ctime = current_time(&ip->i_inode);
312 if (!error) { 311 __mark_inode_dirty(&ip->i_inode, I_DIRTY_SYNC | I_DIRTY_DATASYNC);
313 ip->i_inode.i_ctime = current_time(&ip->i_inode);
314 gfs2_trans_add_meta(ip->i_gl, dibh);
315 gfs2_dinode_out(ip, dibh->b_data);
316 brelse(dibh);
317 }
318 312
319 gfs2_trans_end(sdp); 313 gfs2_trans_end(sdp);
320 314
@@ -616,7 +610,6 @@ static int gfs2_xattr_get(const struct xattr_handler *handler,
616{ 610{
617 struct gfs2_inode *ip = GFS2_I(inode); 611 struct gfs2_inode *ip = GFS2_I(inode);
618 struct gfs2_holder gh; 612 struct gfs2_holder gh;
619 bool need_unlock = false;
620 int ret; 613 int ret;
621 614
622 /* During lookup, SELinux calls this function with the glock locked. */ 615 /* During lookup, SELinux calls this function with the glock locked. */
@@ -625,10 +618,11 @@ static int gfs2_xattr_get(const struct xattr_handler *handler,
625 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); 618 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
626 if (ret) 619 if (ret)
627 return ret; 620 return ret;
628 need_unlock = true; 621 } else {
622 gfs2_holder_mark_uninitialized(&gh);
629 } 623 }
630 ret = __gfs2_xattr_get(inode, name, buffer, size, handler->flags); 624 ret = __gfs2_xattr_get(inode, name, buffer, size, handler->flags);
631 if (need_unlock) 625 if (gfs2_holder_initialized(&gh))
632 gfs2_glock_dq_uninit(&gh); 626 gfs2_glock_dq_uninit(&gh);
633 return ret; 627 return ret;
634} 628}
@@ -749,7 +743,6 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
749 ea_skeleton_call_t skeleton_call, void *private) 743 ea_skeleton_call_t skeleton_call, void *private)
750{ 744{
751 struct gfs2_alloc_parms ap = { .target = blks }; 745 struct gfs2_alloc_parms ap = { .target = blks };
752 struct buffer_head *dibh;
753 int error; 746 int error;
754 747
755 error = gfs2_rindex_update(GFS2_SB(&ip->i_inode)); 748 error = gfs2_rindex_update(GFS2_SB(&ip->i_inode));
@@ -774,13 +767,8 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
774 if (error) 767 if (error)
775 goto out_end_trans; 768 goto out_end_trans;
776 769
777 error = gfs2_meta_inode_buffer(ip, &dibh); 770 ip->i_inode.i_ctime = current_time(&ip->i_inode);
778 if (!error) { 771 __mark_inode_dirty(&ip->i_inode, I_DIRTY_SYNC | I_DIRTY_DATASYNC);
779 ip->i_inode.i_ctime = current_time(&ip->i_inode);
780 gfs2_trans_add_meta(ip->i_gl, dibh);
781 gfs2_dinode_out(ip, dibh->b_data);
782 brelse(dibh);
783 }
784 772
785out_end_trans: 773out_end_trans:
786 gfs2_trans_end(GFS2_SB(&ip->i_inode)); 774 gfs2_trans_end(GFS2_SB(&ip->i_inode));
@@ -891,7 +879,6 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh,
891 struct gfs2_ea_header *ea, struct ea_set *es) 879 struct gfs2_ea_header *ea, struct ea_set *es)
892{ 880{
893 struct gfs2_ea_request *er = es->es_er; 881 struct gfs2_ea_request *er = es->es_er;
894 struct buffer_head *dibh;
895 int error; 882 int error;
896 883
897 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + 2 * RES_EATTR, 0); 884 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + 2 * RES_EATTR, 0);
@@ -908,14 +895,9 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh,
908 if (es->es_el) 895 if (es->es_el)
909 ea_set_remove_stuffed(ip, es->es_el); 896 ea_set_remove_stuffed(ip, es->es_el);
910 897
911 error = gfs2_meta_inode_buffer(ip, &dibh);
912 if (error)
913 goto out;
914 ip->i_inode.i_ctime = current_time(&ip->i_inode); 898 ip->i_inode.i_ctime = current_time(&ip->i_inode);
915 gfs2_trans_add_meta(ip->i_gl, dibh); 899 __mark_inode_dirty(&ip->i_inode, I_DIRTY_SYNC | I_DIRTY_DATASYNC);
916 gfs2_dinode_out(ip, dibh->b_data); 900
917 brelse(dibh);
918out:
919 gfs2_trans_end(GFS2_SB(&ip->i_inode)); 901 gfs2_trans_end(GFS2_SB(&ip->i_inode));
920 return error; 902 return error;
921} 903}
@@ -1111,7 +1093,6 @@ static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el)
1111{ 1093{
1112 struct gfs2_ea_header *ea = el->el_ea; 1094 struct gfs2_ea_header *ea = el->el_ea;
1113 struct gfs2_ea_header *prev = el->el_prev; 1095 struct gfs2_ea_header *prev = el->el_prev;
1114 struct buffer_head *dibh;
1115 int error; 1096 int error;
1116 1097
1117 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + RES_EATTR, 0); 1098 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + RES_EATTR, 0);
@@ -1132,13 +1113,8 @@ static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el)
1132 ea->ea_type = GFS2_EATYPE_UNUSED; 1113 ea->ea_type = GFS2_EATYPE_UNUSED;
1133 } 1114 }
1134 1115
1135 error = gfs2_meta_inode_buffer(ip, &dibh); 1116 ip->i_inode.i_ctime = current_time(&ip->i_inode);
1136 if (!error) { 1117 __mark_inode_dirty(&ip->i_inode, I_DIRTY_SYNC | I_DIRTY_DATASYNC);
1137 ip->i_inode.i_ctime = current_time(&ip->i_inode);
1138 gfs2_trans_add_meta(ip->i_gl, dibh);
1139 gfs2_dinode_out(ip, dibh->b_data);
1140 brelse(dibh);
1141 }
1142 1118
1143 gfs2_trans_end(GFS2_SB(&ip->i_inode)); 1119 gfs2_trans_end(GFS2_SB(&ip->i_inode));
1144 1120
@@ -1268,11 +1244,20 @@ static int gfs2_xattr_set(const struct xattr_handler *handler,
1268 if (ret) 1244 if (ret)
1269 return ret; 1245 return ret;
1270 1246
1271 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); 1247 /* May be called from gfs_setattr with the glock locked. */
1272 if (ret) 1248
1273 return ret; 1249 if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
1250 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
1251 if (ret)
1252 return ret;
1253 } else {
1254 if (WARN_ON_ONCE(ip->i_gl->gl_state != LM_ST_EXCLUSIVE))
1255 return -EIO;
1256 gfs2_holder_mark_uninitialized(&gh);
1257 }
1274 ret = __gfs2_xattr_set(inode, name, value, size, flags, handler->flags); 1258 ret = __gfs2_xattr_set(inode, name, value, size, flags, handler->flags);
1275 gfs2_glock_dq_uninit(&gh); 1259 if (gfs2_holder_initialized(&gh))
1260 gfs2_glock_dq_uninit(&gh);
1276 return ret; 1261 return ret;
1277} 1262}
1278 1263
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 76ce247d3d4b..ca10767ab73d 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -22,7 +22,8 @@ struct vm_fault;
22/* 22/*
23 * Flags for all iomap mappings: 23 * Flags for all iomap mappings:
24 */ 24 */
25#define IOMAP_F_NEW 0x01 /* blocks have been newly allocated */ 25#define IOMAP_F_NEW 0x01 /* blocks have been newly allocated */
26#define IOMAP_F_BOUNDARY 0x02 /* mapping ends at metadata boundary */
26 27
27/* 28/*
28 * Flags that only need to be reported for IOMAP_REPORT requests: 29 * Flags that only need to be reported for IOMAP_REPORT requests: