]> Git Repo - J-linux.git/commitdiff
gfs2: Simplify gfs2_read_super
authorMatthew Wilcox (Oracle) <[email protected]>
Wed, 3 Apr 2024 17:23:50 +0000 (18:23 +0100)
committerAndreas Gruenbacher <[email protected]>
Thu, 2 May 2024 17:24:08 +0000 (19:24 +0200)
Use submit_bio_wait() instead of hand-rolling our own synchronous
wait.  Also allocate the BIO on the stack since we're not deep in
the call stack at this point.

There's no need to kmap the page, since it isn't allocated from HIGHMEM.
Turn the GFP_NOFS allocation into GFP_KERNEL; if the page allocator
enters reclaim, we cannot be called as the filesystem has not yet been
initialised and so has no pages to reclaim.

Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Signed-off-by: Andreas Gruenbacher <[email protected]>
fs/gfs2/ops_fstype.c

index a9f7f0d44227971904397157e46566ebdbca73ce..10bf46867adcd20b675cd6feb7fb9d77d2147194 100644 (file)
@@ -185,22 +185,10 @@ static int gfs2_check_sb(struct gfs2_sbd *sdp, int silent)
        return 0;
 }
 
-static void end_bio_io_page(struct bio *bio)
-{
-       struct page *page = bio->bi_private;
-
-       if (!bio->bi_status)
-               SetPageUptodate(page);
-       else
-               pr_warn("error %d reading superblock\n", bio->bi_status);
-       unlock_page(page);
-}
-
-static void gfs2_sb_in(struct gfs2_sbd *sdp, const void *buf)
+static void gfs2_sb_in(struct gfs2_sbd *sdp, const struct gfs2_sb *str)
 {
        struct gfs2_sb_host *sb = &sdp->sd_sb;
        struct super_block *s = sdp->sd_vfs;
-       const struct gfs2_sb *str = buf;
 
        sb->sb_magic = be32_to_cpu(str->sb_header.mh_magic);
        sb->sb_type = be32_to_cpu(str->sb_header.mh_type);
@@ -240,34 +228,26 @@ static void gfs2_sb_in(struct gfs2_sbd *sdp, const void *buf)
 static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector, int silent)
 {
        struct super_block *sb = sdp->sd_vfs;
-       struct gfs2_sb *p;
        struct page *page;
-       struct bio *bio;
+       struct bio_vec bvec;
+       struct bio bio;
+       int err;
 
-       page = alloc_page(GFP_NOFS);
+       page = alloc_page(GFP_KERNEL);
        if (unlikely(!page))
                return -ENOMEM;
 
-       ClearPageUptodate(page);
-       ClearPageDirty(page);
-       lock_page(page);
-
-       bio = bio_alloc(sb->s_bdev, 1, REQ_OP_READ | REQ_META, GFP_NOFS);
-       bio->bi_iter.bi_sector = sector * (sb->s_blocksize >> 9);
-       __bio_add_page(bio, page, PAGE_SIZE, 0);
+       bio_init(&bio, sb->s_bdev, &bvec, 1, REQ_OP_READ | REQ_META);
+       bio.bi_iter.bi_sector = sector * (sb->s_blocksize >> 9);
+       __bio_add_page(&bio, page, PAGE_SIZE, 0);
 
-       bio->bi_end_io = end_bio_io_page;
-       bio->bi_private = page;
-       submit_bio(bio);
-       wait_on_page_locked(page);
-       bio_put(bio);
-       if (!PageUptodate(page)) {
+       err = submit_bio_wait(&bio);
+       if (err) {
+               pr_warn("error %d reading superblock\n", err);
                __free_page(page);
-               return -EIO;
+               return err;
        }
-       p = kmap(page);
-       gfs2_sb_in(sdp, p);
-       kunmap(page);
+       gfs2_sb_in(sdp, page_address(page));
        __free_page(page);
        return gfs2_check_sb(sdp, silent);
 }
This page took 0.048259 seconds and 4 git commands to generate.