From patchwork Fri Mar 4 16:10:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 8505341 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 30FED9F7CA for ; Fri, 4 Mar 2016 16:13:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2BEB020259 for ; Fri, 4 Mar 2016 16:13:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 39B6720145 for ; Fri, 4 Mar 2016 16:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932522AbcCDQMo (ORCPT ); Fri, 4 Mar 2016 11:12:44 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:43161 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932493AbcCDQMl (ORCPT ); Fri, 4 Mar 2016 11:12:41 -0500 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.15.0.59/8.15.0.59) with SMTP id u24G9RXI031370; Fri, 4 Mar 2016 08:12:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=wJKmn+dsmTqfSB3m4egSEgohB8ODb3VAKFdcryyzLks=; b=pYKpOgyeZqiE0J0ljlYUOBUi29mJNdYje9tYybjyrMKdeY+m4eDwJbaB94WjeWsKxmGf zjkU0jXTm/q/2Z6AOH0zHL0Vo53ekYGzWWe/w9jy2fK7bVEfsHfUh3/rkpPfX7H/Nv97 TlBRXp/Uz4LYxQzV4JJFT9K9hTa0I/GsAVs= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 21f6yj1f44-11 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Fri, 04 Mar 2016 08:12:38 -0800 Received: from localhost.localdomain (192.168.54.13) by mail.thefacebook.com (192.168.16.15) with Microsoft SMTP Server (TLS) id 14.3.248.2; Fri, 4 Mar 2016 08:11:04 -0800 From: Jens Axboe To: , CC: , , , Jens Axboe Subject: [PATCH 09/11] btrfs: add support for write stream IDs Date: Fri, 4 Mar 2016 09:10:51 -0700 Message-ID: <1457107853-8689-10-git-send-email-axboe@fb.com> X-Mailer: git-send-email 2.4.1.168.g1ea28e1 In-Reply-To: <1457107853-8689-1-git-send-email-axboe@fb.com> References: <1457107853-8689-1-git-send-email-axboe@fb.com> MIME-Version: 1.0 X-Originating-IP: [192.168.54.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-03-04_07:, , signatures=0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Both buffered and O_DIRECT supported, and support for iterating the below backing devices for open/close of streams. Signed-off-by: Jens Axboe Signed-off-by: Chris Mason --- fs/btrfs/disk-io.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/extent_io.c | 1 + fs/btrfs/inode.c | 1 + 3 files changed, 71 insertions(+) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 4545e2e2ad45..2fd3b4a6bdcd 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1748,6 +1748,72 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits) return ret; } +static int btrfs_streamid_close(struct btrfs_fs_info *info, int id) +{ + struct btrfs_device *device; + + mutex_lock(&info->fs_devices->device_list_mutex); + list_for_each_entry_rcu(device, &info->fs_devices->devices, dev_list) { + struct backing_dev_info *bdi; + + if (!device->bdev) + continue; + + bdi = blk_get_backing_dev_info(device->bdev); + bdi_streamid_close(bdi, id); + } + mutex_unlock(&info->fs_devices->device_list_mutex); + + return 0; +} + +static int btrfs_streamid_open(struct btrfs_fs_info *info, int id) +{ + struct btrfs_device *device; + int ret = -EINVAL; + + mutex_lock(&info->fs_devices->device_list_mutex); + list_for_each_entry_rcu(device, &info->fs_devices->devices, dev_list) { + struct backing_dev_info *bdi; + + if (!device->bdev) + continue; + + bdi = blk_get_backing_dev_info(device->bdev); + ret = bdi_streamid_open(bdi, id); + if (ret < 0) + break; + } + mutex_unlock(&info->fs_devices->device_list_mutex); + + return ret; +} + +static int btrfs_streamid_open_fn(void *data, unsigned int id) +{ + struct btrfs_fs_info *info = (struct btrfs_fs_info *) data; + int ret = 0; + + /* + * > 0 is success, return it. If we fail, fall through to + * freeing the ID, if we did set it on a device. + */ + ret = btrfs_streamid_open(info, id); + if (ret > 0) + return ret; + + btrfs_streamid_close(info, id); + return ret; +} + +static int btrfs_streamid_close_fn(void *data, unsigned int id) +{ + struct btrfs_fs_info *info = (struct btrfs_fs_info *) data; + + btrfs_streamid_close(info, id); + return 0; +} + static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi) { int err; @@ -1760,6 +1826,9 @@ static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi) bdi->congested_fn = btrfs_congested_fn; bdi->congested_data = info; bdi->capabilities |= BDI_CAP_CGROUP_WRITEBACK; + bdi->streamid_open = btrfs_streamid_open_fn; + bdi->streamid_close = btrfs_streamid_close_fn; + bdi->streamid_data = info; return 0; } diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 392592dc7010..0f1507af8266 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2808,6 +2808,7 @@ static int submit_extent_page(int rw, struct extent_io_tree *tree, bio_add_page(bio, page, page_size, offset); bio->bi_end_io = end_io_func; bio->bi_private = tree; + bio_set_streamid(bio, inode_streamid(page->mapping->host)); if (wbc) { wbc_init_bio(wbc, bio); wbc_account_io(wbc, page, page_size); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index d96f5cf38a2d..77661a1f9e5e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8338,6 +8338,7 @@ static void btrfs_submit_direct(int rw, struct bio *dio_bio, atomic_set(&dip->pending_bios, 0); btrfs_bio = btrfs_io_bio(io_bio); btrfs_bio->logical = file_offset; + bio_set_streamid(io_bio, bio_get_streamid(dio_bio)); if (write) { io_bio->bi_end_io = btrfs_endio_direct_write;