Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4755072rwe; Mon, 17 Apr 2023 18:42:15 -0700 (PDT) X-Google-Smtp-Source: AKy350Yfw2BGgClZyNLkidFz3NVobYG+2owt8XbtfHTcQearK9gjlxnwJdpiFnmoO6aXUSo652H8 X-Received: by 2002:a05:6a00:b8c:b0:63b:7ad1:549c with SMTP id g12-20020a056a000b8c00b0063b7ad1549cmr12342239pfj.6.1681782135637; Mon, 17 Apr 2023 18:42:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681782135; cv=none; d=google.com; s=arc-20160816; b=01+6wBNL9iRpGQ0AuttforJIu8jehaIgmTXA+o+tgHYcT9/zpCNuqd+TqcWq2l6rgA UkTaLrXU5LED5WKs9EiftToz2DsbT5okKtmpf4OUPzTBT3zTaRigPrNmOBNxWJsjGxhG oPS7jKbKRLSp8qp/m6l8wt3NvBUFfZDenf3XP5908CbXBQXeZ3244AwSJjMmiQnIlV5J 8HONCQBhhGyRNNKhSYDicIra5PRcLQ27aEkHZk36Zh3Lb2UkjUkaNVx5f+py8nx3JmRZ Aw2/UmaipTVTsK8Noih1/rtI86RzgULjiIYAFTIydvtBbZHrkWEO+A2JQs/MuU9m6Sa0 dDDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=tI4xcmLYwpmFva3i/dRZyfQFdXSO1OOUgkc/BOul5Ro=; b=yJaNhRrWW7uui7v5AdS9D9ihmXUmMWXC7oGy5xPrjdwtymdMfsNNiuH3KU1zs7XkfG sPl+9stONcRcmZQ9+IwzOmCSKsXIrrSwefQ1h1gLwrlrUzHB9pwmixO45Kdd1qWJbojm mZIV7UhT+MXPIA1ccsRqT3WzGtpBKzR5NjWkAelXsTDrvRXjcXJRMEaBOZ+1v9bEIsqE d6hWc463H6p0ru2iXPeeTfHQ60+9y/ZFkSql0DaWM4FA7gTuwe566pFzbpaC73EEYniS UBKBK/NCNIHdZ6B9xIjF0IZYQ+b1n/d2H9xkohPWDYdMycIpwzIb0k7+Sc+v+FWZlZCh BrbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=2V9e6mUN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b68-20020a62cf47000000b0063b1739532esi12848704pfg.139.2023.04.17.18.42.01; Mon, 17 Apr 2023 18:42:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=2V9e6mUN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230218AbjDRBl2 (ORCPT + 99 others); Mon, 17 Apr 2023 21:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230143AbjDRBlO (ORCPT ); Mon, 17 Apr 2023 21:41:14 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43B555B84 for ; Mon, 17 Apr 2023 18:41:00 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54f97aac3d0so147121987b3.15 for ; Mon, 17 Apr 2023 18:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681782060; x=1684374060; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tI4xcmLYwpmFva3i/dRZyfQFdXSO1OOUgkc/BOul5Ro=; b=2V9e6mUN9Le2shS/G4YvhPJcIGT2cNDZPr1QkNJOacyGU//myujH64KDbejS/tMlXz 4E6nR0HLcdcTv09CWWYmtKIX5wVZpN0ReS4cFCAJVsgaJjGnWqRP+K97KcNMss7R5lc/ 8wSlpIQsxhUI3w04o4cPXpyg3kA0F6KHlojC/d7SlYfU/cCvQzPLbwOg1psSwLmSzRXn Qn3vxYWDKyf/Fn+ASbJ7PU1gdKO1me/kfleFJ2griqgfwNcqIJ9AF057vwZ+pRcgxCsX sF1c9SZLi/nimZi9xbCd1jVXTRuM8JHWnHdMqXKLly0BeGcWX5EH1LSs7jCfFcSZkogo szkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681782060; x=1684374060; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tI4xcmLYwpmFva3i/dRZyfQFdXSO1OOUgkc/BOul5Ro=; b=akRD7qR63m/SRMFyF2VdmTfCNH9yxtOgnH/0ukOE9Pz8s2QBThKiPOB3SHNXP8z8xZ lG/+cDuyKgfkYv/xGdrydvlidgwutLOyozwL0dcuTzOvATzFBmx9wQbaVn8Fc9J5YhH9 x0cyQQhBvXzp/8humwlaVOiUxts5oK5mL1hBCLJ7/fHGreQ3a1pWtxf3UvKjYlIemL/Y jsOavmCCtJkjSkKiQCdW0mgTBEUSUbRTARRiCZPLoy9ei7Cr3sn/rh5/pepq00dBggMv +R8drgkRSAHxkIl/j8Sq/EEQYwlfaLsSh1rZPaTP8YT0L8FHLkv+nhLXcFaLujomT3Uw oQzA== X-Gm-Message-State: AAQBX9dP/tFGyFKNCMd9docWbp3Rw5V3wH08eDEeUQxqMKpfYY2YcAj9 d8eo2gCNtNdcSEKIrBEu/bHkacMsQXg= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:e67a:98b0:942d:86aa]) (user=drosen job=sendgmr) by 2002:a25:d70a:0:b0:b77:ae4b:1b27 with SMTP id o10-20020a25d70a000000b00b77ae4b1b27mr8727839ybg.8.1681782059999; Mon, 17 Apr 2023 18:40:59 -0700 (PDT) Date: Mon, 17 Apr 2023 18:40:04 -0700 In-Reply-To: <20230418014037.2412394-1-drosen@google.com> Mime-Version: 1.0 References: <20230418014037.2412394-1-drosen@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230418014037.2412394-5-drosen@google.com> Subject: [RFC PATCH v3 04/37] fs: Generic function to convert iocb to rw flags From: Daniel Rosenberg To: Miklos Szeredi , bpf@vger.kernel.org, Alexei Starovoitov Cc: Amir Goldstein , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jonathan Corbet , Joanne Koong , Mykola Lysenko , kernel-team@android.com, Alessio Balsini , Alessio Balsini Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alessio Balsini OverlayFS implements its own function to translate iocb flags into rw flags, so that they can be passed into another vfs call. With commit ce71bfea207b4 ("fs: align IOCB_* flags with RWF_* flags") Jens created a 1:1 matching between the iocb flags and rw flags, simplifying the conversion. Reduce the OverlayFS code by making the flag conversion function generic and reusable. Signed-off-by: Alessio Balsini --- fs/overlayfs/file.c | 23 +++++------------------ include/linux/fs.h | 5 +++++ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 7c04f033aadd..759893e4da04 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -15,6 +15,8 @@ #include #include "overlayfs.h" +#define OVL_IOCB_MASK (IOCB_DSYNC | IOCB_HIPRI | IOCB_NOWAIT | IOCB_SYNC) + struct ovl_aio_req { struct kiocb iocb; refcount_t ref; @@ -241,22 +243,6 @@ static void ovl_file_accessed(struct file *file) touch_atime(&file->f_path); } -static rwf_t ovl_iocb_to_rwf(int ifl) -{ - rwf_t flags = 0; - - if (ifl & IOCB_NOWAIT) - flags |= RWF_NOWAIT; - if (ifl & IOCB_HIPRI) - flags |= RWF_HIPRI; - if (ifl & IOCB_DSYNC) - flags |= RWF_DSYNC; - if (ifl & IOCB_SYNC) - flags |= RWF_SYNC; - - return flags; -} - static inline void ovl_aio_put(struct ovl_aio_req *aio_req) { if (refcount_dec_and_test(&aio_req->ref)) { @@ -316,7 +302,8 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter) old_cred = ovl_override_creds(file_inode(file)->i_sb); if (is_sync_kiocb(iocb)) { ret = vfs_iter_read(real.file, iter, &iocb->ki_pos, - ovl_iocb_to_rwf(iocb->ki_flags)); + iocb_to_rw_flags(iocb->ki_flags, + OVL_IOCB_MASK)); } else { struct ovl_aio_req *aio_req; @@ -380,7 +367,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) if (is_sync_kiocb(iocb)) { file_start_write(real.file); ret = vfs_iter_write(real.file, iter, &iocb->ki_pos, - ovl_iocb_to_rwf(ifl)); + iocb_to_rw_flags(ifl, OVL_IOCB_MASK)); file_end_write(real.file); /* Update size */ ovl_copyattr(inode); diff --git a/include/linux/fs.h b/include/linux/fs.h index c85916e9f7db..c849074f44b7 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3009,6 +3009,11 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags) return 0; } +static inline rwf_t iocb_to_rw_flags(int ifl, int iocb_mask) +{ + return ifl & iocb_mask; +} + static inline ino_t parent_ino(struct dentry *dentry) { ino_t res; -- 2.40.0.634.g4ca3ef3211-goog