From nobody Mon Feb 9 20:31:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1567635058; cv=none; d=zoho.com; s=zohoarc; b=nxdAzIxX8MaSWOXD96eGoEWgZyplk6si2MJJqsJwoyz4t3553bWEnb7WE0NAlHY/czuW/7EBSIlq5CAa9OY11Zvuz2CcMdxH1HAIH/TyakydXCqYZ4fbcP0hpPQUdDjJGEGkENACmdkGx2I8IsKUZ9tA/BnjnU9elYAK+boxmX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567635058; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=J2L0IXzCXi2xsedmiyXipbA7L6ebbINxIxuXPbItBbs=; b=R+T9nwucYYqRHEA/EifUi9QLXI2zWNRBBWloNiPV1JrxZPulfMkKL+zxOD8oxUkswD3lVvFl9GQjHADY0LY64CaxiWZN1D9sRh2Cg5OdYzVTZviaHx21lVpAstD4T9Bl4U69a+Lo0SdgMeuOrP5fmycAuciFpBbhfub+eSV3ZTM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail header.i=@wdc.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1567635058763793.9092610088169; Wed, 4 Sep 2019 15:10:58 -0700 (PDT) Received: from localhost ([::1]:40892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5dUM-000258-04 for importer@patchew.org; Wed, 04 Sep 2019 18:10:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56078) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5cOy-0006Jh-EH for qemu-devel@nongnu.org; Wed, 04 Sep 2019 17:01:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5cOt-0007bC-0Y for qemu-devel@nongnu.org; Wed, 04 Sep 2019 17:01:16 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:52308) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i5cOp-0007X8-EZ; Wed, 04 Sep 2019 17:01:07 -0400 Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Sep 2019 05:01:04 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Sep 2019 13:58:01 -0700 Received: from dhcp-10-88-173-181.hgst.com ([10.88.173.181]) by uls-op-cesaip01.wdc.com with ESMTP; 04 Sep 2019 14:01:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1567630867; x=1599166867; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LPK5dv7NDBXIbuHf7ST8MYcA/NaQLO9UasvmcvccZu0=; b=AKe/Oq4A8aSkJR/PD5brS3TKiL5bkbRrPPWTlKkhEr5SMLYJrZODy1pq 2kwPLhw5oFxwNdTUYFGYu1bIeFKY4xNLlt3ecid9EXKFL03Om+I+RjlBQ 7A5FM6AyKrKlPWsy3zDJFCMeHukk2/Mja/oqcpbUTPYeKqEdLJlPgfeGT Cf/ETlNX4DRVms2GNVGRXAnLUnmjwHfZImY7hveH06Oztf6zqJ4eANzld fOiOo4tnA5G8eX529cCxuRuT/LgP5ztDqO0Fkrwte1vsJyre6qaHmpyW8 SmSq6nZsDpimjZt+s8gapbGfoagMAzTGdNTOF8bXiGIyW78lEP2A5mUb7 Q==; IronPort-SDR: 2R7GuYyY6Tuj6dacHV55eIMJnzBgsRLxpq+zyprLLsrBpe5NcaRPhnSKc8MH+4/QFALI9x5hhR lDzDPtb/oLY0B545h0eYf+ir4/A6RAtP9dtO+FG/eeR4WEXCmJ9j0Yxjq1XCjt7Qc8CwUuEp0V OicX4bUnxVxEejKN42JUlB8kK6RpQBObTQZMMcLIfdtc0BcYUNt1/nFPjPOhDLIwGzQqrY5QMG 4YWfp/Asl0GC79phfw8ZuBAoxFhn6OH8g2Erh5g9mo7pQwhhsjDqiOomO5bcRahK4Dz2Lah8u4 RSs= X-IronPort-AV: E=Sophos;i="5.64,468,1559491200"; d="scan'208";a="117451661" IronPort-SDR: HVnHIv23UbwaJZt+pgfCJYhBmf30iHrQXV+/sbFdXHzPue5hG2monWpgJIVXJyFC3DrattTv3s PNa+xOwHqL64IqPVTvKfL7sSViOroQyxOhUisWYNjiP/sbW2tJYfuHAGeX2llmNPW8piR1yeZP 5veBR6KLBZgyH5a+oE9AFUHqRM0ACJG0p78Bzi1kd9Oope9vPofomZvIQeVeWJb6g8FR5V93IK jJb+7VBJ3WF/52vw2HYWZVdF6GODE617g89mUV0up2uSdbA6CxgGno/hojmHl34CjdZZ4faEhd +nIutWjbpX5Zb8DRm3sGvyZY IronPort-SDR: y9e8+neQLroy0eQNSwHL/xZOw84PdorXa1Ip0129/hx1itYP55WMHycJhhPVwHB2cbD9fQCaMt Agkz8DmK7wCVqN8uO3SM9xd7cSU6Um1y1EhAD4Exl1n8be9JKHeItOJSy5CzTAMg/SO02L+7fw zJlfzwjccnkEH2EbzJae4Ly1RDIwEiO1sFKCl6O5h/Cb9zhn0whylWTbQkenlXP+I4yt49rMIH VmowHurfx+qhVG0khK0vuhdUpR4l6Y2HseifEXNve437cnMYCuxuViHgJDc0ni/iH2kKs26Faa OU4= WDCIronportException: Internal From: Dmitry Fomichev To: Paolo Bonzini , Kevin Wolf , Max Reitz , "Michael S . Tsirkin" , Stefan Hajnoczi , John Snow Date: Wed, 4 Sep 2019 17:00:58 -0400 Message-Id: <20190904210100.10501-3-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904210100.10501-1-dmitry.fomichev@wdc.com> References: <20190904210100.10501-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 216.71.154.42 Subject: [Qemu-devel] [PATCH v6 2/4] raw: Recognize zoned backing devices 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: Dmitry Fomichev , Alistair Francis , qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The purpose of this patch is to recognize a zoned block device (ZBD) when it is opened as a raw file. The new code initializes the zoned model propery introduced by the previous commit. This commit is Linux-specific as it gets the Zoned Block Device Model value (none/host-managed/host-aware) from sysfs on the host. In order to avoid code duplication in file-posix.c, a common helper function is added to read values of sysfs entries under /sys/block//queue. This way, the existing function that reads the value of "max_segments" entry and the the new function that reads "zoned" value both share the same helper code. Signed-off-by: Dmitry Fomichev --- block/file-posix.c | 75 ++++++++++++++++++++++++++++++++++++++-------- block/io.c | 5 ++++ 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index fbeb0068db..c7e1aff6eb 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1067,15 +1067,13 @@ static int sg_get_max_transfer_length(int fd) #endif } =20 -static int sg_get_max_segments(int fd) +static int hdev_read_blk_queue_entry(int fd, const char *key, + char *buf, int buf_len) { #ifdef CONFIG_LINUX - char buf[32]; - const char *end; char *sysfspath =3D NULL; int ret; int sysfd =3D -1; - long max_segments; struct stat st; =20 if (fstat(fd, &st)) { @@ -1083,23 +1081,45 @@ static int sg_get_max_segments(int fd) goto out; } =20 - sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments= ", - major(st.st_rdev), minor(st.st_rdev)); + sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", + major(st.st_rdev), minor(st.st_rdev), key); sysfd =3D open(sysfspath, O_RDONLY); if (sysfd =3D=3D -1) { ret =3D -errno; goto out; } do { - ret =3D read(sysfd, buf, sizeof(buf) - 1); + ret =3D read(sysfd, buf, buf_len - 1); } while (ret =3D=3D -1 && errno =3D=3D EINTR); if (ret < 0) { ret =3D -errno; - goto out; } else if (ret =3D=3D 0) { ret =3D -EIO; + } +out: + if (sysfd !=3D -1) { + close(sysfd); + } + g_free(sysfspath); + return ret; +#else + return -ENOTSUP; +#endif +} + +static int sg_get_max_segments(int fd) +{ +#ifdef CONFIG_LINUX + char buf[32]; + const char *end; + int ret; + long max_segments; + + ret =3D hdev_read_blk_queue_entry(fd, "max_segments", buf, sizeof(buf)= ); + if (ret < 0) { goto out; } + buf[ret] =3D 0; /* The file is ended with '\n', pass 'end' to accept that. */ ret =3D qemu_strtol(buf, &end, 10, &max_segments); @@ -1108,22 +1128,45 @@ static int sg_get_max_segments(int fd) } =20 out: - if (sysfd !=3D -1) { - close(sysfd); - } - g_free(sysfspath); return ret; #else return -ENOTSUP; #endif } =20 +static BdrvZonedModel hdev_get_zoned_model(int fd) +{ +#ifdef CONFIG_LINUX + char buf[32]; + BdrvZonedModel zm =3D BDRV_ZONED_MODEL_NONE; + int ret; + + ret =3D hdev_read_blk_queue_entry(fd, "zoned", buf, sizeof(buf)); + if (ret < 0) { + goto out; + } + + buf[ret - 1] =3D '\0'; /* replace the newline character with NULL */ + if (strcmp(buf, "host-managed") =3D=3D 0) { + zm =3D BDRV_ZONED_MODEL_HM; + } else if (strcmp(buf, "host-aware") =3D=3D 0) { + zm =3D BDRV_ZONED_MODEL_HA; + } + +out: + return zm; +#else + return BDRV_ZONED_MODEL_NONE; +#endif +} + static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s =3D bs->opaque; + int ret; =20 if (bs->sg) { - int ret =3D sg_get_max_transfer_length(s->fd); + ret =3D sg_get_max_transfer_length(s->fd); =20 if (ret > 0 && ret <=3D BDRV_REQUEST_MAX_BYTES) { bs->bl.max_transfer =3D pow2floor(ret); @@ -1133,6 +1176,12 @@ static void raw_refresh_limits(BlockDriverState *bs,= Error **errp) if (ret > 0) { bs->bl.max_transfer =3D MIN(bs->bl.max_transfer, ret * getpage= size()); } + + } + + ret =3D hdev_get_zoned_model(s->fd); + if (ret >=3D 0) { + bs->bl.zoned_model =3D ret; } =20 raw_probe_alignment(bs, s->fd, errp); diff --git a/block/io.c b/block/io.c index 0fa10831ed..147c320061 100644 --- a/block/io.c +++ b/block/io.c @@ -157,6 +157,11 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error *= *errp) return; } bdrv_merge_limits(&bs->bl, &bs->file->bs->bl); + + /* Propagate zoned model */ + if (!bs->probed) { + bs->bl.zoned_model =3D bs->file->bs->bl.zoned_model; + } } else { bs->bl.min_mem_alignment =3D 512; bs->bl.opt_mem_alignment =3D getpagesize(); --=20 2.21.0