linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@lst.de>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ming Lei <ming.lei@redhat.com>,
	"Ewan D . Milne" <emilne@redhat.com>
Subject: [PATCH 1/2] block: move partitions check code into single helper
Date: Fri,  5 Feb 2021 10:17:07 +0800	[thread overview]
Message-ID: <20210205021708.1498711-2-ming.lei@redhat.com> (raw)
In-Reply-To: <20210205021708.1498711-1-ming.lei@redhat.com>

No functional change, make code more readable, and prepare for
supporting safe re-read partitions.

Cc: Ewan D. Milne <emilne@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/partitions/core.c | 51 ++++++++++++++++++++++++++++++-----------
 1 file changed, 37 insertions(+), 14 deletions(-)

diff --git a/block/partitions/core.c b/block/partitions/core.c
index b1cdf88f96e2..154013ea8623 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -599,17 +599,15 @@ static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,
 	return true;
 }
 
-int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
+static int blk_check_partitions(struct gendisk *disk,
+		struct block_device *bdev, struct parsed_partitions **s)
 {
-	struct parsed_partitions *state;
-	int ret = -EAGAIN, p;
-
-	if (!disk_part_scan_enabled(disk))
-		return 0;
+	int ret = -EAGAIN;
+	struct parsed_partitions *state = check_partition(disk, bdev);
 
-	state = check_partition(disk, bdev);
 	if (!state)
-		return 0;
+		goto out;
+
 	if (IS_ERR(state)) {
 		/*
 		 * I/O error reading the partition table.  If we tried to read
@@ -647,15 +645,40 @@ int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
 			goto out_free_state;
 	}
 
+out:
+	*s = state;
+	return 0;
+
+out_free_state:
+	free_partitions(state);
+	*s = NULL;
+	return ret;
+}
+
+int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
+{
+	struct parsed_partitions *state;
+	int ret, p;
+
+	if (!disk_part_scan_enabled(disk))
+		return 0;
+
+	ret = blk_check_partitions(disk, bdev, &state);
+	if (ret != 0)
+		return ret;
+
+	if (!state)
+		return 0;
+
 	/* tell userspace that the media / partition table may have changed */
 	kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
 
-	for (p = 1; p < state->limit; p++)
-		if (!blk_add_partition(disk, bdev, state, p))
-			goto out_free_state;
-
-	ret = 0;
-out_free_state:
+	for (p = 1; p < state->limit; p++) {
+		if (!blk_add_partition(disk, bdev, state, p)) {
+			ret = -EAGAIN;
+			break;
+		}
+	}
 	free_partitions(state);
 	return ret;
 }
-- 
2.29.2


  reply	other threads:[~2021-02-05  2:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05  2:17 [PATCH 0/2] block: avoid to drop & re-add partitions if partitions aren't changed Ming Lei
2021-02-05  2:17 ` Ming Lei [this message]
2021-02-05  2:17 ` [PATCH 2/2] " Ming Lei
2021-02-05  7:14   ` Christoph Hellwig
2021-02-05  7:30     ` Ming Lei
2021-02-15  4:03 ` [PATCH 0/2] " Ming Lei
2021-02-16  8:44   ` Christoph Hellwig
2021-02-17  3:07     ` Ming Lei
2021-02-17  7:16       ` Christoph Hellwig
2021-02-18  7:57         ` Ming Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210205021708.1498711-2-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=emilne@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).