Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3544DC04FF3 for ; Mon, 24 May 2021 16:44:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DD847610FC for ; Mon, 24 May 2021 16:44:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD847610FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llDh3-0007RJ-95 for qemu-devel@archiver.kernel.org; Mon, 24 May 2021 12:44:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llDZU-00079m-L4; Mon, 24 May 2021 12:36:52 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:38807) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1llDZS-0002lo-Jw; Mon, 24 May 2021 12:36:52 -0400 Received: by mail-ej1-x62d.google.com with SMTP id i7so24932697ejc.5; Mon, 24 May 2021 09:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K5qPvgjroW4HFZ0QOxtJbrxU7fNNc6UbjjlweCupMYc=; b=HNzmLz8bIGRGr2Edn3bbBj5hVWJTK0ApnCLryKAwDdz3QU7xw/V3x0acbR3ldrYrV3 6ZHvcSJmYuTsHUQ1Z1qGrDAwOdx9LNLtFyqoc+Qj7tpIGTd6LVDtwT0OtCIlfKKc+jPo tpUqmEAxnKEnrdvYiFApNmDavaeqJhhetavaCaGygOe+H5D/P//k3tGZgIPKErr9oqhX lgX8vuoHvbbRJLEJfKdfNyXX/u0dGgwCAp8yGDYrIW5PiIchQOjI4HTqjBZ6lGdNisZL dloBKfPqCrVX6gM7TLOzb0f0wK3YnixBcd+ds0MgefcXWaqcZxvEFRDOncZm7W8RVQ5y PT2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=K5qPvgjroW4HFZ0QOxtJbrxU7fNNc6UbjjlweCupMYc=; b=bOQlHG+GhHnbQoSBX3NKrPGsqM8AaFv7FNNarzNHgX4O8oNY1hoNE3DiHw6nxTtnK8 FrZSjPHJ7nS0qpVQp9zRB5iTRSK6z4JxC5uoU3QbC93LTbCHJXwiw3ddakFUUfKjtLPX FzSzpoCL27rkM9hjaaZnUD9eUTsmrQ5AyjjXWsrSnUanLyVO50r8m2secmkrm4B+9tmx L8rh9ytcYy1TONUq3Uvve9ZouDa2PwbbnoptEm0sLdIHL/6xZ/MKA4NUKQiGairGVnRT kWFOyEM+E6EW83NdwiY7+FDiy7caW5RCpadoWXHKicudMqkbxEp7fyB0OZvAuuJfIT7Z 8RFg== X-Gm-Message-State: AOAM532H91LjooVwxBtVh8MvXkj0lHI4jC4meHcivg681f/3dgFZFHq+ yCP19bQfWtklUgEbknaOiwdd4N9Cdnyb1A== X-Google-Smtp-Source: ABdhPJwN1KhPgMhgA3TfVilwxOX5Xj9HrT0eWPja2SZzBJYpg0WxF+aNTeFMtDv6EbVcQ7hjXhrpBw== X-Received: by 2002:a17:906:76c6:: with SMTP id q6mr11778984ejn.387.1621874208860; Mon, 24 May 2021 09:36:48 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id n8sm7967684ejl.0.2021.05.24.09.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 09:36:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 3/6] file-posix: fix max_iov for /dev/sg devices Date: Mon, 24 May 2021 18:36:42 +0200 Message-Id: <20210524163645.382940-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524163645.382940-1-pbonzini@redhat.com> References: <20210524163645.382940-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Even though it was only called for devices that have bs->sg set (which must be character devices), sg_get_max_segments looked at /sys/dev/block which only works for block devices. On Linux the sg driver has its own way to provide the maximum number of iovecs in a scatter/gather list. Signed-off-by: Paolo Bonzini --- block/file-posix.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index e5ef006aee..77a45083a6 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1179,6 +1179,17 @@ static int sg_get_max_segments(int fd, struct stat *st) int sysfd = -1; long max_segments; + if (S_ISCHR(st->st_mode)) { + if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) == 0) { + return ret; + } + return -EIO; + } + + if (!S_ISBLK(st->st_mode)) { + return -ENOTSUP; + } + sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments", major(st->st_rdev), minor(st->st_rdev)); sysfd = open(sysfspath, O_RDONLY); -- 2.31.1