From nobody Tue Oct 25 15:17:07 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MxbC81csNz4g4dx; Tue, 25 Oct 2022 15:17:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MxbC80xJsz3xfC; Tue, 25 Oct 2022 15:17:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666711028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=r5gAkU5C1UslurHeygb7eI7RFhrQGh1r+dqDczt0LLw=; b=H4Ovs5PQMUC8ud58wORBqfBcX0EfwpCfiivcaqfwuFOhG4ACoGfJFNS7aOT/0ggA1oNE8v tFjzZFS5JTV6vsvHPvs9MvyisDyPRE3br71cRr8fQt7bpsMgRT+7K9XK6eEpbWAH+pYkID Y/K4YH1lwVmb7E34IispfJPmqaiYcfSHlQf8qSUYv2TweCJYwBWuAuEEeCkItYGhxRZdIF OAQlshihu2TQgcs92kX5hyiEBD5y4u9SWy4nC9GhuUDSQXpiyPr7lVPzM2gFPWoaOFzmJr nfsDeDONNLNoJ8K8YiF5ADc4+XAb26Py47uH8Ko+2/vkbNWg30DA6peAq64R5w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MxbC7709Czj6g; Tue, 25 Oct 2022 15:17:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29PFH7Yp023213; Tue, 25 Oct 2022 15:17:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29PFH7dh023212; Tue, 25 Oct 2022 15:17:07 GMT (envelope-from git) Date: Tue, 25 Oct 2022 15:17:07 GMT Message-Id: <202210251517.29PFH7dh023212@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 46f5c828961e - main - bhyve: Address warnings in blockif_proc() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 46f5c828961e64646c46ff9e3bc8e55f46f3e7bb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666711028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=r5gAkU5C1UslurHeygb7eI7RFhrQGh1r+dqDczt0LLw=; b=VqTLoUQ475VHlgTHceE5LY2KwL5U0urXNm3e9oPiASsJQoMT31zRZO2x0cuhrIU2BplndT 6jY8b3fmxEN+FipXQfkxll+1VBz9j//p54Kfn+JBLfwad2ZYPmaduadsnnjckzeSgGydrH ndbawJeborWW+ANBsYdoNOocYfwqBaztAojxTWhiZPZXcfLBq+E6yjRFMtsq+h2i5ONP5+ ozkiPcCeaK1h3Njt/StIvVGoLv1EnnOc4ZH2soGGq2d/Yorne+YWn5Z1iT6hS9yitekeJh Ml20bh//abKk+srWRSxy/kINs1AXDjR3c9S8qm08yuXRee6Drk6331LTFfvOZg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666711028; a=rsa-sha256; cv=none; b=qARhWkWsaPkFyVWeI3sv2UOF0gFjtfdVKtwR+w6Kfn8JGAkKz2urymd7AQgMyFmetekEvn GqsHnVVFxPbkTv/KiB6TeYzHV9iRgqpLHoisES+1V/C6EozK7VJChxjmSqG5rmInyTtUl1 GSydBNerf0rp6IeEo+1EGjzyjW0VD5s7Sou4pBMc9wyv7tcNU5dI79g7tLQ/kUgSlCa7Cc IHCx6mlJzYdZhzpwOfDCj9X5EF7Knoa+AdQ2tMW46DDTs8YdE+rUxWIHrIsYmn/3Ii1MaE fjKNCiEYehpzDY2iz5qnUU7dPiAWm9KdwE5gjA7iieAN6DtAgIJSB/m7ojPOAg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=46f5c828961e64646c46ff9e3bc8e55f46f3e7bb commit 46f5c828961e64646c46ff9e3bc8e55f46f3e7bb Author: Mark Johnston AuthorDate: 2022-10-25 13:16:23 +0000 Commit: Mark Johnston CommitDate: 2022-10-25 15:16:56 +0000 bhyve: Address warnings in blockif_proc() - Use unsigned types for all arithmetic. Use a new signed variable for holding the return value of pread() and pwrite(). - Handle short I/O from pwrite(). MFC after: 1 week --- usr.sbin/bhyve/block_if.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/usr.sbin/bhyve/block_if.c b/usr.sbin/bhyve/block_if.c index b22ca140a80e..c8454a679bcd 100644 --- a/usr.sbin/bhyve/block_if.c +++ b/usr.sbin/bhyve/block_if.c @@ -233,35 +233,39 @@ blockif_flush_bc(struct blockif_ctxt *bc) static void blockif_proc(struct blockif_ctxt *bc, struct blockif_elem *be, uint8_t *buf) { + struct spacectl_range range; struct blockif_req *br; off_t arg[2]; - ssize_t clen, len, off, boff, voff; + ssize_t n; + size_t clen, len, off, boff, voff; int i, err; - struct spacectl_range range; br = be->be_req; + assert(br->br_resid >= 0); + if (br->br_iovcnt <= 1) buf = NULL; err = 0; switch (be->be_op) { case BOP_READ: if (buf == NULL) { - if ((len = preadv(bc->bc_fd, br->br_iov, br->br_iovcnt, - br->br_offset)) < 0) + if ((n = preadv(bc->bc_fd, br->br_iov, br->br_iovcnt, + br->br_offset)) < 0) err = errno; else - br->br_resid -= len; + br->br_resid -= n; break; } i = 0; off = voff = 0; while (br->br_resid > 0) { len = MIN(br->br_resid, MAXPHYS); - if (pread(bc->bc_fd, buf, len, br->br_offset + - off) < 0) { + n = pread(bc->bc_fd, buf, len, br->br_offset + off); + if (n < 0) { err = errno; break; } + len = (size_t)n; boff = 0; do { clen = MIN(len - boff, br->br_iov[i].iov_len - @@ -286,11 +290,11 @@ blockif_proc(struct blockif_ctxt *bc, struct blockif_elem *be, uint8_t *buf) break; } if (buf == NULL) { - if ((len = pwritev(bc->bc_fd, br->br_iov, br->br_iovcnt, - br->br_offset)) < 0) + if ((n = pwritev(bc->bc_fd, br->br_iov, br->br_iovcnt, + br->br_offset)) < 0) err = errno; else - br->br_resid -= len; + br->br_resid -= n; break; } i = 0; @@ -312,13 +316,14 @@ blockif_proc(struct blockif_ctxt *bc, struct blockif_elem *be, uint8_t *buf) } boff += clen; } while (boff < len); - if (pwrite(bc->bc_fd, buf, len, br->br_offset + - off) < 0) { + + n = pwrite(bc->bc_fd, buf, len, br->br_offset + off); + if (n < 0) { err = errno; break; } - off += len; - br->br_resid -= len; + off += n; + br->br_resid -= n; } break; case BOP_FLUSH: