diff mbox

[5/7] btrfs-progs: Document logic of btrfs_read_dev_super

Message ID 1512463189-24724-6-git-send-email-nborisov@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Nikolay Borisov Dec. 5, 2017, 8:39 a.m. UTC
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 disk-io.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Qu Wenruo Dec. 5, 2017, 9:21 a.m. UTC | #1
On 2017年12月05日 16:39, Nikolay Borisov wrote:
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>  disk-io.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/disk-io.c b/disk-io.c
> index 3d8785d5bb37..40077d4919c6 100644
> --- a/disk-io.c
> +++ b/disk-io.c
> @@ -1419,6 +1419,23 @@ static int check_super(struct btrfs_super_block *sb, unsigned sbflags)
>  	return -EIO;
>  }
>  
> +/*
> + * btrfs_read_dev_super - read a valid superblock from a block device
> + * @fd:		file descrioptor of the device
> + * @sb:		buffer where the superblock is going to be read in
> + * @sb_bytenr:  offset of the particular superblock copie we want
> + * @sbflags:	flags controlling how the superblock is read.
> + *
> + * This function is used by various btrfs comands to obtain a valid superblock.
> + *
> + * It's mode of operation is controlled by the @sb_bytenr and @sbdflags
> + * parameters. If SBREAD_RECOVER flag is set and @sb_bytenr is
> + * BTRFS_SUPER_INFO_OFFSET then the function reads all 3 superblock copies and
> + * returns the newest one. If SBREAD_RECOVER is not set then only a single
> + * copy is read, which one is decided by @sb_bytenr. If @sb_bytenr !=
> + * BTRFS_SUPER_INFO_OFFSET then the sbflags is effectively ignored and only a
> + * single copy is read.

Although the logic is not as straightforward, it's still acceptable and
the comment does makes it clearer.

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> + */
>  int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
>  			 unsigned sbflags)
>  {
>
diff mbox

Patch

diff --git a/disk-io.c b/disk-io.c
index 3d8785d5bb37..40077d4919c6 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1419,6 +1419,23 @@  static int check_super(struct btrfs_super_block *sb, unsigned sbflags)
 	return -EIO;
 }
 
+/*
+ * btrfs_read_dev_super - read a valid superblock from a block device
+ * @fd:		file descrioptor of the device
+ * @sb:		buffer where the superblock is going to be read in
+ * @sb_bytenr:  offset of the particular superblock copie we want
+ * @sbflags:	flags controlling how the superblock is read.
+ *
+ * This function is used by various btrfs comands to obtain a valid superblock.
+ *
+ * It's mode of operation is controlled by the @sb_bytenr and @sbdflags
+ * parameters. If SBREAD_RECOVER flag is set and @sb_bytenr is
+ * BTRFS_SUPER_INFO_OFFSET then the function reads all 3 superblock copies and
+ * returns the newest one. If SBREAD_RECOVER is not set then only a single
+ * copy is read, which one is decided by @sb_bytenr. If @sb_bytenr !=
+ * BTRFS_SUPER_INFO_OFFSET then the sbflags is effectively ignored and only a
+ * single copy is read.
+ */
 int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
 			 unsigned sbflags)
 {