From patchwork Tue Aug 28 00:03:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10577689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC19915A7 for ; Tue, 28 Aug 2018 00:03:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A30EF29DA9 for ; Tue, 28 Aug 2018 00:03:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9748F29DBB; Tue, 28 Aug 2018 00:03:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4D5129DC1 for ; Tue, 28 Aug 2018 00:03:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727345AbeH1Dw1 (ORCPT ); Mon, 27 Aug 2018 23:52:27 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:44105 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727206AbeH1Dw1 (ORCPT ); Mon, 27 Aug 2018 23:52:27 -0400 Received: by mail-pf1-f194.google.com with SMTP id k21-v6so316635pff.11 for ; Mon, 27 Aug 2018 17:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KXDfPDSLmduTHjzoQClsx5DkuHAltQZjXTGXQfC5xN8=; b=aruch9K3y6ExtUPm4k0KuKXDiVtviUcpTBk+Jvqyq1CoMXZHroIsoAGUHZSm5hNkV2 CNXQWgDi1kgwOEQPKGD2T7nUmLjOiiB01ux3lfSosMrURsIrSnTxF1qNsfFjFOZotCG2 Y+IOUFrIvkOTKpCqnQGXQ7tb0Jw986iig1ON5vdKAHh8kMzaLPlumcHGk3a73nXtZr2s IqtVt2kjNEsEztvFZNIlVIXSqrwDuQTc4Afg/Tufdq4piPywZy4QpWO23yctuHKKpASL hRiI1Y6v1mEbsXoV5wC7fDExgSODNxXC7CFNuN1ZTy/XmdMEBIqN0YMsnsBkFfJzZ8gM kaSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KXDfPDSLmduTHjzoQClsx5DkuHAltQZjXTGXQfC5xN8=; b=DTr7T8nfwMtxD9mPJfGZXfZONRU5ZIouaLc7dCrx4Ui3tt9Yg2gSWfhEZgVFbw81UE 6XCs2aG9N8jSvjXWbhOWsACaMMNDU0aCTcs5qlj6ea7BkkW7akx0sRFjql/IhqmHDEG4 HwakCbgBxEDMtE8eJHB4/bM2SZWD73QGKXCOnUSBFDSRma1rssoBB7WHc/dnWQ3BtbBO YOpZj46LlaF+f1Yj4x6KqxTMP9Ug/vDFIHdGj53zxpe/9N5LVhxknbmdzlPy92opPgAU PYafW9ea7UZB2SKZ6M5agyecyyYgJTEKEowlJ9qfhZyb0sO4L6qIjnI6bGMAjw3wi7gq yWSQ== X-Gm-Message-State: APzg51CUxtIUzRtmazro5U7irAnUh/eTrn2bVgf6c1Kxaa1BRprC1zMI FG48HTYfOH1c0jQQ+zlgDm5nbw== X-Google-Smtp-Source: ANB0VdbjSgk6PJ4X+9FD92RM7JCOphDmfZhjZFTBVMoTtR2yxQw1mkADun4FQP25Wf8PBNObaStw0w== X-Received: by 2002:a63:8f05:: with SMTP id n5-v6mr14182378pgd.131.1535414611930; Mon, 27 Aug 2018 17:03:31 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::7:5f0c]) by smtp.gmail.com with ESMTPSA id z22-v6sm455315pgc.67.2018.08.27.17.03.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Aug 2018 17:03:31 -0700 (PDT) From: Omar Sandoval To: linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, Al Viro Cc: David Sterba , kernel-team@fb.com, Mark Fasheh , Joel Becker Subject: [RFC PATCH v2 3/6] ocfs2: use iocb->private instead of bh->b_private Date: Mon, 27 Aug 2018 17:03:16 -0700 Message-Id: <3140f34d27f1ad45a75073284ee36347b2da9cd9.1535414064.git.osandov@fb.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval As part of simplifying all of the private data passed around for direct I/O, bh->b_private will no longer be passed to dio_iodone_t. Instead, filesystems should use iocb->private. ocfs2 already uses iocb->private for storing a couple of flag bits, but we can use it as a tagged pointer and hide all of the messiness in helpers. Cc: Mark Fasheh Cc: Joel Becker Signed-off-by: Omar Sandoval --- fs/ocfs2/aops.c | 19 ++++++++------- fs/ocfs2/aops.h | 64 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 93ca23c56b07..fc4a18b6ad3c 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -2104,12 +2104,13 @@ struct ocfs2_dio_write_ctxt { }; static struct ocfs2_dio_write_ctxt * -ocfs2_dio_alloc_write_ctx(struct buffer_head *bh, int *alloc) +ocfs2_dio_alloc_write_ctx(struct kiocb *iocb, int *alloc) { - struct ocfs2_dio_write_ctxt *dwc = NULL; + struct ocfs2_dio_write_ctxt *dwc; - if (bh->b_private) - return bh->b_private; + dwc = ocfs2_iocb_private(iocb); + if (dwc) + return dwc; dwc = kmalloc(sizeof(struct ocfs2_dio_write_ctxt), GFP_NOFS); if (dwc == NULL) @@ -2118,7 +2119,7 @@ ocfs2_dio_alloc_write_ctx(struct buffer_head *bh, int *alloc) dwc->dw_zero_count = 0; dwc->dw_orphaned = 0; dwc->dw_writer_pid = task_pid_nr(current); - bh->b_private = dwc; + ocfs2_iocb_set_private(iocb, dwc); *alloc = 1; return dwc; @@ -2184,7 +2185,7 @@ static int ocfs2_dio_wr_get_block(struct kiocb *iocb, struct inode *inode, bh_result->b_state = 0; } - dwc = ocfs2_dio_alloc_write_ctx(bh_result, &first_get_block); + dwc = ocfs2_dio_alloc_write_ctx(iocb, &first_get_block); if (unlikely(dwc == NULL)) { ret = -ENOMEM; mlog_errno(ret); @@ -2408,6 +2409,7 @@ static int ocfs2_dio_end_io(struct kiocb *iocb, ssize_t bytes, void *private) { + struct ocfs2_dio_write_ctxt *dwc; struct inode *inode = file_inode(iocb->ki_filp); int level; int ret = 0; @@ -2415,8 +2417,9 @@ static int ocfs2_dio_end_io(struct kiocb *iocb, /* this io's submitter should not have unlocked this before we could */ BUG_ON(!ocfs2_iocb_is_rw_locked(iocb)); - if (bytes > 0 && private) - ret = ocfs2_dio_end_io_write(inode, private, offset, bytes); + dwc = ocfs2_iocb_private(iocb); + if (bytes > 0 && dwc) + ret = ocfs2_dio_end_io_write(inode, dwc, offset, bytes); ocfs2_iocb_clear_rw_locked(iocb); diff --git a/fs/ocfs2/aops.h b/fs/ocfs2/aops.h index 3494a62ed749..2c3219e0c010 100644 --- a/fs/ocfs2/aops.h +++ b/fs/ocfs2/aops.h @@ -63,32 +63,54 @@ int ocfs2_size_fits_inline_data(struct buffer_head *di_bh, u64 new_size); int ocfs2_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create); -/* all ocfs2_dio_end_io()'s fault */ -#define ocfs2_iocb_is_rw_locked(iocb) \ - test_bit(0, (unsigned long *)&iocb->private) + +/* + * Direct I/O uses iocb->private as a tagged pointer. The bottom two bits + * defined below are used for communication between ocfs2_dio_end_io() and + * ocfs2_file_write/read_iter(). + */ +#define OCFS2_IOCB_RW_LOCK 1 +#define OCFS2_IOCB_RW_LOCK_LEVEL 2 + +static inline void *ocfs2_iocb_private(struct kiocb *iocb) +{ + return (void *)((unsigned long)iocb->private & ~3); +} + +static inline void ocfs2_iocb_set_private(struct kiocb *iocb, void *private) +{ + iocb->private = (void *)(((unsigned long)iocb->private & 3) | + ((unsigned long)private & ~3)); +} + +static inline bool ocfs2_iocb_is_rw_locked(struct kiocb *iocb) +{ + return (unsigned long)iocb->private & OCFS2_IOCB_RW_LOCK; +} + static inline void ocfs2_iocb_set_rw_locked(struct kiocb *iocb, int level) { - set_bit(0, (unsigned long *)&iocb->private); + unsigned long private = (unsigned long)iocb->private; + + private |= OCFS2_IOCB_RW_LOCK; if (level) - set_bit(1, (unsigned long *)&iocb->private); + private |= OCFS2_IOCB_RW_LOCK_LEVEL; else - clear_bit(1, (unsigned long *)&iocb->private); + private &= ~OCFS2_IOCB_RW_LOCK_LEVEL; + iocb->private = (void *)private; } -/* - * Using a named enum representing lock types in terms of #N bit stored in - * iocb->private, which is going to be used for communication between - * ocfs2_dio_end_io() and ocfs2_file_write/read_iter(). - */ -enum ocfs2_iocb_lock_bits { - OCFS2_IOCB_RW_LOCK = 0, - OCFS2_IOCB_RW_LOCK_LEVEL, - OCFS2_IOCB_NUM_LOCKS -}; - -#define ocfs2_iocb_clear_rw_locked(iocb) \ - clear_bit(OCFS2_IOCB_RW_LOCK, (unsigned long *)&iocb->private) -#define ocfs2_iocb_rw_locked_level(iocb) \ - test_bit(OCFS2_IOCB_RW_LOCK_LEVEL, (unsigned long *)&iocb->private) +static inline void ocfs2_iocb_clear_rw_locked(struct kiocb *iocb) +{ + unsigned long private = (unsigned long)iocb->private; + + private &= ~OCFS2_IOCB_RW_LOCK; + iocb->private = (void *)private; +} + +static inline bool ocfs2_iocb_rw_locked_level(struct kiocb *iocb) +{ + return (unsigned long)iocb->private & OCFS2_IOCB_RW_LOCK_LEVEL; +} #endif /* OCFS2_FILE_H */