Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1508514rdb; Thu, 7 Dec 2023 00:36:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHD48vn+BkOguxAKCkpvxQQekAL/vTNlim71sd5t3i00rQDDGJBSeO8uvm0n14GdsjDyger X-Received: by 2002:a9d:7d11:0:b0:6d9:9e1c:491e with SMTP id v17-20020a9d7d11000000b006d99e1c491emr2319207otn.51.1701938214998; Thu, 07 Dec 2023 00:36:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701938214; cv=none; d=google.com; s=arc-20160816; b=rKvZ1AuW9giJ512e+7BEspF8nFtWxpdJS5W+cEL5eR+kOhxY26W+bQQ8nMZk3qsM9S dRmJ7AjLK2Lrph+8YpidbUhL1cLvIRPqS3Vt88Fm6F8O+vqRJ4ZN4ixEnH1Tljwf2K5x avi88yppARqyxhZXcp3akmtMdgspUNjHiy/RMMNy338r2ZfnYnBzMsEIX7Sgtdm1eoQ0 8nMavmRGUgVqG+U9C1RDuZb8gvDD3TjwbNmo9y7B1XpzFM5UNVVnu09AXmVKYe4xAL9S LTqBBSgAt2h9D+mrv/ATOcN9IbuN49p4lPAJNS2twBVBV37Jva7wo9bsl7KEQfQFEH9b hU6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=u099gzjDXzJ4GHKJVOCEEgCI+HNpjyaO5+j80X95e2M=; fh=JJ6XuJws04ZTDoXMtogHpkKD8YDwoIWFzY7xNjodiaE=; b=YARrXH9I4ZKQs+gHphCOf30K/s1v7mtBgSHqicguKL/SfZ9YDH/clUpw+ib+D/tv1N TB6ZupInsOy69J1MkDu6tJOnI4yeBXxkgjWsCXoGZ9RRxjAj/svzsSkWD/vxT99Pgwkw WF/LWXhxcUvStLFk5vu7LymOLCFDg2R75BdLjRbAcne7Qw8Jmo54hK4luP7ETPddT01E WYN9u0WB3ylzGxH5y2CCBvcT7PqR3JwqxmI5kVzdD1kXS0Ybqq88FWDBgTVh1S/MrPqb VQDBHmSPOlIgtw/wSJdyIVAcXD5152CQ2almM1XcCd2+mnAH6b+bUEQYPYe9xodOUsqp wGkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="mI/U/5XK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id bv127-20020a632e85000000b005c671034474si780423pgb.532.2023.12.07.00.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 00:36:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="mI/U/5XK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 74F5080268E2; Thu, 7 Dec 2023 00:36:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231305AbjLGIga (ORCPT + 99 others); Thu, 7 Dec 2023 03:36:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231193AbjLGIgZ (ORCPT ); Thu, 7 Dec 2023 03:36:25 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F25D9D4A; Thu, 7 Dec 2023 00:36:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=u099gzjDXzJ4GHKJVOCEEgCI+HNpjyaO5+j80X95e2M=; b=mI/U/5XKN2ARAgTCnAZnGUNidm llAtiKBODd6zoC4Hxgv9jXUJwfuZv9ii9kpYhc/luds3zKQ9WsoEy4/BBPf02mzaBFNhScotUAGHj i9+vmqwFDUzJdnNBRLfZZpSY2+L0Rs3JvosSJsCKItFgmwtnn4tyR8c+IJxQ8ayqsNFHYmxaU0L0B 0k9Och0sMoDnUBHBNScqTNviA7lAEYLiI2b3zHTWbF+tDx2bPbpTfUjFSAXGTwGD0sNC4jiBTA8NE Q+pS9cVMv5u14b8UjE37FoKM/7BmUwnoPYOcWXgyW0COzhdnIFcyBTesXOqiLufj7LwG8D/VhjBQc 3vITmcWQ==; Received: from hch by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1rB9rr-00CEn1-0o; Thu, 07 Dec 2023 08:36:23 +0000 Date: Thu, 7 Dec 2023 00:36:23 -0800 From: Christoph Hellwig To: Sergei Shtepa Cc: axboe@kernel.dk, hch@infradead.org, corbet@lwn.net, snitzer@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, viro@zeniv.linux.org.uk, brauner@kernel.org, linux-block@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Sergei Shtepa Subject: Re: [PATCH v6 07/11] blksnap: difference storage and chunk Message-ID: References: <20231124165933.27580-1-sergei.shtepa@linux.dev> <20231124165933.27580-8-sergei.shtepa@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231124165933.27580-8-sergei.shtepa@linux.dev> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 07 Dec 2023 00:36:52 -0800 (PST) > +static inline bool unsupported_mode(const umode_t m) > +{ > + return (S_ISCHR(m) || S_ISFIFO(m) || S_ISSOCK(m)); > +} > + > +static inline bool unsupported_flags(const unsigned int flags) > +{ > + if (!(flags | O_RDWR)) { > + pr_err("Read and write access is required\n"); > + return true; > + } > + if (!(flags | O_EXCL)) { > + pr_err("Exclusive access is required\n"); > + return true; > + } You probably want to positively check the allowed flags and types to be more future proof. I'd also drop these very easy to trigger messages. > + if (S_ISBLK(file_inode(file)->i_mode)) { Splitting the blk and regular file open path into separate helpers would improve readability a lot I think. > + /* > + * The block device is opened non-exclusively. > + * It should be exclusive to open the file whose descriptor is > + * passed to the module. > + */ > + bdev = blkdev_get_by_dev(dev_id, > + BLK_OPEN_READ | BLK_OPEN_WRITE, > + NULL, NULL); Note that this will have some interesting interaction with the patches from Jan to optionally disallow any other write for exclusively opened block devices. But given that right now we don't support using the original device as backing store, this probably should become an exclusive open anyway.