From: Liu Bo <bo.li.liu@oracle.com>
To: Stefan Behrens <sbehrens@giantdisaster.de>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 07/26] Btrfs: add two more find_device() methods
Date: Thu, 8 Nov 2012 22:24:51 +0800 [thread overview]
Message-ID: <20121108142450.GA3034@gmail.com> (raw)
In-Reply-To: <700c11c33955b15829597d5de5d890814be97ee9.1352217243.git.sbehrens@giantdisaster.de>
On Tue, Nov 06, 2012 at 05:38:25PM +0100, Stefan Behrens wrote:
> The new function btrfs_find_device_missing_or_by_path() will be
> used for the device replace procedure. This function itself calls
> the second new function btrfs_find_device_by_path().
> Unfortunately, it is not possible to currently make the rest of the
> code use these functions as well, since all functions that look
> similar at first view are all a little bit different in what they
> are doing. But in the future, new code could benefit from these
> two new functions, and currently, device replace uses them.
>
> Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
> ---
> fs/btrfs/volumes.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> fs/btrfs/volumes.h | 5 ++++
> 2 files changed, 79 insertions(+)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index eeed97d..bcd3097 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -1512,6 +1512,80 @@ error_undo:
> goto error_brelse;
> }
>
> +int btrfs_find_device_by_path(struct btrfs_root *root, char *device_path,
> + struct btrfs_device **device)
> +{
> + int ret = 0;
> + struct btrfs_super_block *disk_super;
> + u64 devid;
> + u8 *dev_uuid;
> + struct block_device *bdev;
> + struct buffer_head *bh = NULL;
> +
> + *device = NULL;
> + mutex_lock(&uuid_mutex);
Since the caller have held volume_mutex, we can get rid of the
mutex_lock here, can't we?
> + bdev = blkdev_get_by_path(device_path, FMODE_READ,
> + root->fs_info->bdev_holder);
> + if (IS_ERR(bdev)) {
> + ret = PTR_ERR(bdev);
> + bdev = NULL;
> + goto out;
> + }
> +
> + set_blocksize(bdev, 4096);
> + invalidate_bdev(bdev);
> + bh = btrfs_read_dev_super(bdev);
> + if (!bh) {
> + ret = -EINVAL;
> + goto out;
> + }
I made a scan for this 'get bdev & bh' in the code, I think
maybe we can make a function,
func_get(device_path, flags, mode, &bdev, &bh, flush)
where we need to take care of setting bdev = NULL, bh = NULL, and
'flush' is for filemap_bdev(). Besides, we also need to make
some proper error handling.
thanks,
liubo
> + disk_super = (struct btrfs_super_block *)bh->b_data;
> + devid = btrfs_stack_device_id(&disk_super->dev_item);
> + dev_uuid = disk_super->dev_item.uuid;
> + *device = btrfs_find_device(root, devid, dev_uuid,
> + disk_super->fsid);
> + brelse(bh);
> + if (!*device)
> + ret = -ENOENT;
> +out:
> + mutex_unlock(&uuid_mutex);
> + if (bdev)
> + blkdev_put(bdev, FMODE_READ);
> + return ret;
> +}
> +
> +int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
> + char *device_path,
> + struct btrfs_device **device)
> +{
> + *device = NULL;
> + if (strcmp(device_path, "missing") == 0) {
> + struct list_head *devices;
> + struct btrfs_device *tmp;
> +
> + devices = &root->fs_info->fs_devices->devices;
> + /*
> + * It is safe to read the devices since the volume_mutex
> + * is held by the caller.
> + */
> + list_for_each_entry(tmp, devices, dev_list) {
> + if (tmp->in_fs_metadata && !tmp->bdev) {
> + *device = tmp;
> + break;
> + }
> + }
> +
> + if (!*device) {
> + pr_err("btrfs: no missing device found\n");
> + return -ENOENT;
> + }
> +
> + return 0;
> + } else {
> + return btrfs_find_device_by_path(root, device_path, device);
> + }
> +}
> +
> /*
> * does all the dirty work required for changing file system's UUID.
> */
> diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
> index 1789cda..657bb12 100644
> --- a/fs/btrfs/volumes.h
> +++ b/fs/btrfs/volumes.h
> @@ -268,6 +268,11 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
> struct btrfs_fs_devices **fs_devices_ret);
> int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
> void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices);
> +int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
> + char *device_path,
> + struct btrfs_device **device);
> +int btrfs_find_device_by_path(struct btrfs_root *root, char *device_path,
> + struct btrfs_device **device);
> int btrfs_add_device(struct btrfs_trans_handle *trans,
> struct btrfs_root *root,
> struct btrfs_device *device);
> --
> 1.8.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2012-11-08 14:25 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-06 16:38 [PATCH 00/26] Btrfs: Add device replace code Stefan Behrens
2012-11-06 16:38 ` [PATCH 01/26] Btrfs: rename the scrub context structure Stefan Behrens
2012-11-06 16:38 ` [PATCH 02/26] Btrfs: remove the block device pointer from the scrub context struct Stefan Behrens
2012-11-06 16:38 ` [PATCH 03/26] Btrfs: make the scrub page array dynamically allocated Stefan Behrens
2012-11-06 16:38 ` [PATCH 04/26] Btrfs: in scrub repair code, optimize the reading of mirrors Stefan Behrens
2012-11-06 16:38 ` [PATCH 05/26] Btrfs: in scrub repair code, simplify alloc error handling Stefan Behrens
2012-11-06 16:38 ` [PATCH 06/26] Btrfs: cleanup scrub bio and worker wait code Stefan Behrens
2012-11-06 16:38 ` [PATCH 07/26] Btrfs: add two more find_device() methods Stefan Behrens
2012-11-08 14:24 ` Liu Bo [this message]
2012-11-12 16:50 ` Stefan Behrens
2012-11-06 16:38 ` [PATCH 08/26] Btrfs: Pass fs_info to btrfs_num_copies() instead of mapping_tree Stefan Behrens
2012-11-06 16:38 ` [PATCH 09/26] Btrfs: pass fs_info to btrfs_map_block() " Stefan Behrens
2012-11-06 16:38 ` [PATCH 10/26] Btrfs: add btrfs_scratch_superblock() function Stefan Behrens
2012-11-06 16:38 ` [PATCH 11/26] Btrfs: pass fs_info instead of root Stefan Behrens
2012-11-06 16:38 ` [PATCH 12/26] Btrfs: avoid risk of a deadlock in btrfs_handle_error Stefan Behrens
2012-11-06 16:38 ` [PATCH 13/26] Btrfs: enhance btrfs structures for device replace support Stefan Behrens
2012-11-06 16:38 ` [PATCH 14/26] Btrfs: introduce a btrfs_dev_replace_item type Stefan Behrens
2012-11-06 16:38 ` [PATCH 15/26] Btrfs: add a new source file with device replace code Stefan Behrens
2012-11-08 14:50 ` Liu Bo
2012-11-08 17:24 ` Stefan Behrens
2012-11-09 0:44 ` Liu Bo
2012-11-09 10:19 ` Stefan Behrens
2012-11-09 14:45 ` Liu Bo
2012-11-12 17:21 ` Stefan Behrens
2012-11-06 16:38 ` [PATCH 16/26] Btrfs: disallow mutually exclusiv admin operations from user mode Stefan Behrens
2012-11-06 16:38 ` [PATCH 17/26] Btrfs: disallow some operations on the device replace target device Stefan Behrens
2012-11-06 16:38 ` [PATCH 18/26] Btrfs: handle errors from btrfs_map_bio() everywhere Stefan Behrens
2012-11-06 16:38 ` [PATCH 19/26] Btrfs: add code to scrub to copy read data to another disk Stefan Behrens
2012-11-07 0:30 ` Tsutomu Itoh
2012-11-07 10:30 ` Stefan Behrens
2012-11-06 16:38 ` [PATCH 20/26] Btrfs: change core code of btrfs to support the device replace operations Stefan Behrens
2012-11-06 16:38 ` [PATCH 21/26] Btrfs: introduce GET_READ_MIRRORS functionality for btrfs_map_block() Stefan Behrens
2012-11-06 16:38 ` [PATCH 22/26] Btrfs: changes to live filesystem are also written to replacement disk Stefan Behrens
2012-11-06 16:38 ` [PATCH 23/26] Btrfs: optionally avoid reads from device replace source drive Stefan Behrens
2012-11-06 16:38 ` [PATCH 24/26] Btrfs: increase BTRFS_MAX_MIRRORS by one for dev replace Stefan Behrens
2012-11-09 10:47 ` David Pottage
2012-11-09 11:23 ` Stefan Behrens
2012-11-06 16:38 ` [PATCH 25/26] Btrfs: allow repair code to include target disk when searching mirrors Stefan Behrens
2012-11-06 16:38 ` [PATCH 26/26] Btrfs: add support for device replace ioctls Stefan Behrens
[not found] ` <CAGy7UtjR+kZoBYWaeg=-jHbJHQh4pe3Jt5cwX-rTQEBHFkQ-YQ@mail.gmail.com>
2012-11-06 18:57 ` [PATCH 00/26] Btrfs: Add device replace code Stefan Behrens
2012-11-06 19:20 ` Hugo Mills
2012-11-06 22:48 ` Zach Brown
2012-11-07 10:29 ` Stefan Behrens
2012-11-07 2:14 ` Tsutomu Itoh
2012-11-07 13:12 ` Stefan Behrens
2012-11-08 12:50 ` Goffredo Baroncelli
2012-11-08 17:31 ` Stefan Behrens
2012-11-08 18:41 ` Goffredo Baroncelli
2012-11-09 10:02 ` Michael Kjörling
2012-11-13 16:25 ` Bart Noordervliet
2012-11-14 11:42 ` Stefan Behrens
2012-11-08 0:59 ` Chris Mason
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=20121108142450.GA3034@gmail.com \
--to=bo.li.liu@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=sbehrens@giantdisaster.de \
/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).