Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3561785rwo; Fri, 4 Aug 2023 06:50:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElG+HSjBQ5dXXa4FGPL68GXZgjjLouckptHvtvy9RfbCK9UJd8YXEghyjavA8F8bvpbyXr X-Received: by 2002:a17:906:cc4a:b0:99b:6687:6107 with SMTP id mm10-20020a170906cc4a00b0099b66876107mr1336052ejb.5.1691157058777; Fri, 04 Aug 2023 06:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691157058; cv=none; d=google.com; s=arc-20160816; b=Pg5zc4s2jKBCay9bF3RJP83YwcGuMtc8C6voraV+qTBcGux9Db7SM/q91C/iDlDc2b ZNabjhWJerPQm/zsaUoQntJeWj9wxxcBuSrYlkZiJhKV2xRJFykuJGXMlL0TJQfjpKWY U0sp3mJkopbVZsJsWG3uQ2XlC7BE/jpi5jrJ6E5GHh0eXkfii0WYoBjWwnFDKC25M08h N3OgPMI3reQafqJQL1I9qKMBOe+YIozHN/5cTXIkd3TdNAnEV46HZ7VKUZJJVAtvVLrL HimWj5Ug2EtBa7DC2p16r3OHzCyeJ8OH2eXHdpJ7oTNncA7Sotr7oyb1Direto6vua0n jMSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/PSucnWQdCSSwhW59bqPEA79MtMmsRFldRQW3qSRU0U=; fh=2+k2UmE8LvafU5qNzgAjM/Dn4M5GGukEmX+hFN4rQ+Y=; b=cvXjO9C+tCT7CZ/7o4MtHn0cRws27OOWVqllse2usP8FxbZu8QX2l5xRaWp2UMnknj kVayeCbrxlkhwppZLD20MIAVzetvwJ87LdjxcKbxZX4r8Ca/smFU/uCbHEcorMkTJEZ3 gZaXz5qO1y3UG/olFAy5HIMRPr1dV65bLUWdog5pIjBhkcXde407cbzwcco57AcDUSh5 yJY7vHXJz+Lrt5V7kvHYlXorB6pvP0FDUbHk7Cep3tMxOL/PEOTmQuCJxR+RJfochmaX zs4qcM9ld7TrB8EEjcSkKlXVUvRJhAooyg/QhAaP9EGlll3+zod5bj4gux2hBci5m1Ra x4+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FubS05X3; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p17-20020a1709061b5100b0099b42c9082bsi1590441ejg.508.2023.08.04.06.50.33; Fri, 04 Aug 2023 06:50:58 -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=@redhat.com header.s=mimecast20190719 header.b=FubS05X3; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230328AbjHDNP3 (ORCPT + 99 others); Fri, 4 Aug 2023 09:15:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229786AbjHDNPO (ORCPT ); Fri, 4 Aug 2023 09:15:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D26849E1 for ; Fri, 4 Aug 2023 06:13:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691154823; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/PSucnWQdCSSwhW59bqPEA79MtMmsRFldRQW3qSRU0U=; b=FubS05X3tZatKlNdL1G4bUONYJ3k9qoY9sm2KtlmK2lBYnbOWNIRz1+S5/pV2JT5TbFGFz t5P+cD6jTXAHodFzIIpxLlxJ6uzrx3l5B9rcMoEePEDOEOWw24dpNBMeX1REDZjPkBNrdt qxJmNcxU3ZmaSNaCf4Mu5KatTy6W7Bs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-644-UfFS_D__P02OO0SOFrv8qw-1; Fri, 04 Aug 2023 09:13:42 -0400 X-MC-Unique: UfFS_D__P02OO0SOFrv8qw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 950FD8022EF; Fri, 4 Aug 2023 13:13:41 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AE8DF7FB6; Fri, 4 Aug 2023 13:13:40 +0000 (UTC) From: David Howells To: Ilya Dryomov , Xiubo Li Cc: David Howells , Jeff Layton , Dongsheng Yang , ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 05/18] rbd: Use ceph_databuf for rbd_obj_read_sync() Date: Fri, 4 Aug 2023 14:13:14 +0100 Message-ID: <20230804131327.2574082-6-dhowells@redhat.com> In-Reply-To: <20230804131327.2574082-1-dhowells@redhat.com> References: <20230804131327.2574082-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 Supply a ceph_databuf to rbd_obj_read_sync() to convey the data. Signed-off-by: David Howells --- drivers/block/rbd.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 08d0908d0583..2a161b03dd7a 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -4762,13 +4762,10 @@ static void rbd_free_disk(struct rbd_device *rbd_dev) static int rbd_obj_read_sync(struct rbd_device *rbd_dev, struct ceph_object_id *oid, struct ceph_object_locator *oloc, - void *buf, int buf_len) - + struct ceph_databuf *dbuf, int len) { struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc; struct ceph_osd_request *req; - struct page **pages; - int num_pages = calc_pages_for(0, buf_len); int ret; req = ceph_osdc_alloc_request(osdc, NULL, 1, false, GFP_KERNEL); @@ -4779,15 +4776,8 @@ static int rbd_obj_read_sync(struct rbd_device *rbd_dev, ceph_oloc_copy(&req->r_base_oloc, oloc); req->r_flags = CEPH_OSD_FLAG_READ; - pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL); - if (IS_ERR(pages)) { - ret = PTR_ERR(pages); - goto out_req; - } - - osd_req_op_extent_init(req, 0, CEPH_OSD_OP_READ, 0, buf_len, 0, 0); - osd_req_op_extent_osd_data_pages(req, 0, pages, buf_len, 0, false, - true); + osd_req_op_extent_init(req, 0, CEPH_OSD_OP_READ, 0, len, 0, 0); + osd_req_op_extent_osd_databuf(req, 0, dbuf); ret = ceph_osdc_alloc_messages(req, GFP_KERNEL); if (ret) @@ -4795,9 +4785,6 @@ static int rbd_obj_read_sync(struct rbd_device *rbd_dev, ceph_osdc_start_request(osdc, req); ret = ceph_osdc_wait_request(osdc, req); - if (ret >= 0) - ceph_copy_from_page_vector(pages, buf, 0, ret); - out_req: ceph_osdc_put_request(req); return ret; @@ -4810,12 +4797,18 @@ static int rbd_obj_read_sync(struct rbd_device *rbd_dev, */ static int rbd_dev_v1_header_info(struct rbd_device *rbd_dev) { - struct rbd_image_header_ondisk *ondisk = NULL; + struct rbd_image_header_ondisk *ondisk; + struct ceph_databuf *dbuf = NULL; u32 snap_count = 0; u64 names_size = 0; u32 want_count; int ret; + dbuf = ceph_databuf_alloc(1, sizeof(*ondisk), GFP_KERNEL); + if (!dbuf) + return -ENOMEM; + ondisk = kmap_ceph_databuf_page(dbuf, 0); + /* * The complete header will include an array of its 64-bit * snapshot ids, followed by the names of those snapshots as @@ -4826,17 +4819,18 @@ static int rbd_dev_v1_header_info(struct rbd_device *rbd_dev) do { size_t size; - kfree(ondisk); - size = sizeof (*ondisk); size += snap_count * sizeof (struct rbd_image_snap_ondisk); size += names_size; - ondisk = kmalloc(size, GFP_KERNEL); - if (!ondisk) - return -ENOMEM; + + ret = -ENOMEM; + if (size > dbuf->limit && + ceph_databuf_reserve(dbuf, size - dbuf->limit, + GFP_KERNEL) < 0) + goto out; ret = rbd_obj_read_sync(rbd_dev, &rbd_dev->header_oid, - &rbd_dev->header_oloc, ondisk, size); + &rbd_dev->header_oloc, dbuf, size); if (ret < 0) goto out; if ((size_t)ret < size) { @@ -4845,6 +4839,7 @@ static int rbd_dev_v1_header_info(struct rbd_device *rbd_dev) size, ret); goto out; } + if (!rbd_dev_ondisk_valid(ondisk)) { ret = -ENXIO; rbd_warn(rbd_dev, "invalid header"); @@ -4858,8 +4853,8 @@ static int rbd_dev_v1_header_info(struct rbd_device *rbd_dev) ret = rbd_header_from_disk(rbd_dev, ondisk); out: - kfree(ondisk); - + kunmap_local(ondisk); + ceph_databuf_release(dbuf); return ret; }