From patchwork Thu Feb 15 13:05:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558370 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD3B8C48BC4 for ; Thu, 15 Feb 2024 13:10:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681765.1060756 (Exim 4.92) (envelope-from ) id 1rabVb-0007ae-1v; Thu, 15 Feb 2024 13:10:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681765.1060756; Thu, 15 Feb 2024 13:10:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabVa-0007aV-VH; Thu, 15 Feb 2024 13:10:34 +0000 Received: by outflank-mailman (input) for mailman id 681765; Thu, 15 Feb 2024 13:10:33 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabRZ-0002yD-P0 for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:06:25 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2a07:de40:b251:101:10:150:64:1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 05b67721-cc03-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:06:25 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8E16D22031; Thu, 15 Feb 2024 13:06:24 +0000 (UTC) Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 5DF61139D0; Thu, 15 Feb 2024 13:06:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id 4UaHFVAMzmW3FQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:24 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 05b67721-cc03-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002384; h=from:from:reply-to: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=87vA+v/yqSIw13sXcaxXTXhvJpR4gCj67AXmDFAMYsw=; b=HD/PUmo7iajzRJRmv5GvMx4aXD/9HOxHWCNarSFpPIqNhxjvPnMNSkn+h7FVMT+zzl4Kel BNSF9ruffO9492OvZlDnu9So4OiRXtHR1CgyRHs+ennHo7Ai+HHqDp7mfEgQo9YaUMHYOI YLrBAFdEQNvYkyTQTmq9K+BFK+8c7ms= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002384; h=from:from:reply-to: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=87vA+v/yqSIw13sXcaxXTXhvJpR4gCj67AXmDFAMYsw=; b=HD/PUmo7iajzRJRmv5GvMx4aXD/9HOxHWCNarSFpPIqNhxjvPnMNSkn+h7FVMT+zzl4Kel BNSF9ruffO9492OvZlDnu9So4OiRXtHR1CgyRHs+ennHo7Ai+HHqDp7mfEgQo9YaUMHYOI YLrBAFdEQNvYkyTQTmq9K+BFK+8c7ms= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 13/21] tools/xen-9pfsd: add 9pfs read request support Date: Thu, 15 Feb 2024 14:05:01 +0100 Message-Id: <20240215130509.24008-14-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b="HD/PUmo7" X-Spamd-Result: default: False [4.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email,citrix.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[20.42%] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 8E16D22031 X-Spamd-Bar: ++++ Add the read request of the 9pfs protocol. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk Acked-by: Anthony PERARD --- V2: - make error check more readable (Jason Andryuk) V4: - add directory read support V5: - rewinddir() if reading a directory and offset is 0 (Jason Andryuk) --- tools/9pfsd/io.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 1832c6b06e..ba2d4a436e 100644 --- a/tools/9pfsd/io.c +++ b/tools/9pfsd/io.c @@ -33,6 +33,7 @@ #define P9_CMD_WALK 110 #define P9_CMD_OPEN 112 #define P9_CMD_CREATE 114 +#define P9_CMD_READ 116 #define P9_CMD_WRITE 118 #define P9_CMD_CLUNK 120 #define P9_CMD_STAT 124 @@ -1245,6 +1246,94 @@ static void p9_stat(struct ring *ring, struct p9_header *hdr) free_fid(device, fidp); } +static void p9_read(struct ring *ring, struct p9_header *hdr) +{ + device *device = ring->device; + uint32_t fid; + uint64_t off; + unsigned int len; + uint32_t count; + void *buf; + struct p9_fid *fidp; + int ret; + + ret = fill_data(ring, "ULU", &fid, &off, &count); + if ( ret != 3 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp = get_fid_ref(device, fid); + if ( !fidp || !fidp->opened ) + { + errno = EBADF; + goto err; + } + + len = count; + buf = ring->buffer + sizeof(*hdr) + sizeof(uint32_t); + + if ( fidp->isdir ) + { + struct dirent *dirent; + struct stat st; + struct p9_stat p9s; + + if ( off == 0 ) + rewinddir(fidp->data); + + while ( len != 0 ) + { + errno = 0; + dirent = readdir(fidp->data); + if ( !dirent ) + { + if ( errno ) + goto err; + break; + } + if ( fstatat(fidp->fd, dirent->d_name, &st, 0) < 0 ) + goto err; + fill_p9_stat(device, &p9s, &st, dirent->d_name); + if ( p9s.size + sizeof(p9s.size) > len ) + { + seekdir(fidp->data, dirent->d_off); + break; + } + fill_buffer_at(&buf, "s", &p9s); + len -= p9s.size + sizeof(p9s.size); + } + } + else + { + while ( len != 0 ) + { + ret = pread(fidp->fd, buf, len, off); + if ( ret <= 0 ) + break; + len -= ret; + buf += ret; + off += ret; + } + if ( ret < 0 && len == count ) + goto err; + } + + buf = ring->buffer + sizeof(*hdr) + sizeof(uint32_t); + len = count - len; + fill_buffer(ring, hdr->cmd + 1, hdr->tag, "D", &len, buf); + + out: + free_fid(device, fidp); + + return; + + err: + p9_error(ring, hdr->tag, errno); + goto out; +} + static void p9_write(struct ring *ring, struct p9_header *hdr) { device *device = ring->device; @@ -1369,6 +1458,10 @@ void *io_thread(void *arg) p9_create(ring, &hdr); break; + case P9_CMD_READ: + p9_read(ring, &hdr); + break; + case P9_CMD_WRITE: p9_write(ring, &hdr); break;