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 5B106C433ED for ; Tue, 18 May 2021 08:44:22 +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 DE42A6124C for ; Tue, 18 May 2021 08:44:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DE42A6124C 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]:59004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1livKt-0003ko-Nr for qemu-devel@archiver.kernel.org; Tue, 18 May 2021 04:44:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49104) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1livFv-0003YA-2P; Tue, 18 May 2021 04:39:11 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:33465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1livFp-00047e-3r; Tue, 18 May 2021 04:39:07 -0400 Received: by mail-wr1-x432.google.com with SMTP id n2so9306887wrm.0; Tue, 18 May 2021 01:39:04 -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=kqnw26a5iqDSb7hT+L7wOoBaXhKxzsGqK8GVNRWOjZLD4IZCXzCfMbc7T4RVZq+iWs wcAX7FM1i2jHao4iANkfuoVhfaVLoQpXoQVQFkeKZ16FatPRXcyISR2ujqmQk5JrvOEs be5kyw8MYtUn5hOn/7buJsV71Pq2Wu4IIPfdz3lYoRZNaFMPBcY3vjFHSwa5HmKGmHL7 G8kptMLwYJUCnJCldI0H+2UfiUlHn1SlNDI+WMgihSjdIIJuF8/IV2OL5zByY74y4vTd sYmQWba1MRPzIaKcQgRI3Jpfi0+QwsxPLS485u1k/YLMBFgtw9uaoAoW1zOjEGA83r3J eXqw== 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=dVYHS1yiRNRC5fhix6E0tZ5QTWiynPKuEhVkT4bmAH7PANlSpimOq9Ps/sB1eF1Jya Hy4gt1QZ2/AUwk+mCR11CpwinNlhMU/5SV7fBKQajgPr/1Hjoi4VamyqGVMyKbM+1Ghf d3g4FNK195HzLCt/jCi2Msw86JN3G6fNNYvF5JKzCAsIUNxelvFteR0q0ZLl63D+mjer BPDfFKG73xfjGGQeSGrpIVGQBxphY5Sylw/6cEKx6acAE+GYJ36pj6swGuWdzGRK+EUx DIdakgHXZ4yaW3Qu0Dn5POZJ8o2NclGNy9hNCsU7okT3bsF2VntL57LzVEzlcECtiAys Qp1Q== X-Gm-Message-State: AOAM532V2ZK/9oE3ujz3l+mkHioSJ2A1/VeVop9uAYU+xs1KLqiXC3W3 w3epEVwO9tp8Z5Uj3s5g2+gbK4VhfeoHXg== X-Google-Smtp-Source: ABdhPJyTBDuXFmijGtKl6oX052ClG1jXC81Z+o/sT2+flVgZedN6Bxkj5vfFILB6xdPAwFPf+Qe0IQ== X-Received: by 2002:a5d:4805:: with SMTP id l5mr5350095wrq.142.1621327143462; Tue, 18 May 2021 01:39:03 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id y6sm70959wmy.23.2021.05.18.01.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 01:39:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 2/5] file-posix: fix max_iov for /dev/sg devices Date: Tue, 18 May 2021 10:38:58 +0200 Message-Id: <20210518083901.97369-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518083901.97369-1-pbonzini@redhat.com> References: <20210518083901.97369-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x432.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.25, 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