[PATCH 13/29] tools/xenlogd: add 9pfs write request support

Juergen Gross posted 29 patches 2 years, 3 months ago
Only 18 patches received!
There is a newer version of this series
[PATCH 13/29] tools/xenlogd: add 9pfs write request support
Posted by Juergen Gross 2 years, 3 months ago
Add the write request of the 9pfs protocol.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 tools/xenlogd/io.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/tools/xenlogd/io.c b/tools/xenlogd/io.c
index 6e92667fab..6b4692ca67 100644
--- a/tools/xenlogd/io.c
+++ b/tools/xenlogd/io.c
@@ -32,6 +32,7 @@
 #define P9_CMD_WALK       110
 #define P9_CMD_OPEN       112
 #define P9_CMD_CREATE     114
+#define P9_CMD_WRITE      118
 #define P9_CMD_CLUNK      120
 #define P9_CMD_STAT       124
 
@@ -1010,6 +1011,51 @@ static void p9_create(device *device, struct p9_header *hdr)
     fill_buffer(device, hdr->cmd + 1, hdr->tag, "QU", &qid, &iounit);
 }
 
+static void p9_write(device *device, struct p9_header *hdr)
+{
+    uint32_t fid;
+    uint64_t off;
+    unsigned int len;
+    uint32_t written;
+    void *buf;
+    struct p9_fid *fidp;
+    int ret;
+
+    ret = fill_data(device, "ULD", &fid, &off, &len, device->buffer);
+    if ( ret != 3 )
+    {
+        p9_error(device, hdr->tag, EINVAL);
+        return;
+    }
+
+    fidp = find_fid(device, fid);
+    if ( !fidp || !fidp->opened || fidp->isdir )
+    {
+        p9_error(device, hdr->tag, EBADF);
+        return;
+    }
+
+    buf = device->buffer;
+
+    while ( len != 0 )
+    {
+        ret = pwrite(fidp->fd, buf, len, off);
+        if ( ret < 0 )
+            break;
+        len -= ret;
+        buf += ret;
+        off += ret;
+    }
+
+    written = buf - device->buffer;
+    if ( written == 0 )
+    {
+        p9_error(device, hdr->tag, errno);
+        return;
+    }
+    fill_buffer(device, hdr->cmd + 1, hdr->tag, "U", &written);
+}
+
 static void p9_clunk(device *device, struct p9_header *hdr)
 {
     uint32_t fid;
@@ -1182,6 +1228,10 @@ void *io_thread(void *arg)
                 p9_create(device, &hdr);
                 break;
 
+            case P9_CMD_WRITE:
+                p9_write(device, &hdr);
+                break;
+
             case P9_CMD_CLUNK:
                 p9_clunk(device, &hdr);
                 break;
-- 
2.35.3
Re: [PATCH 13/29] tools/xenlogd: add 9pfs write request support
Posted by Jason Andryuk 2 years, 3 months ago
On Wed, Nov 1, 2023 at 5:54 AM Juergen Gross <jgross@suse.com> wrote:
>
> Add the write request of the 9pfs protocol.
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>  tools/xenlogd/io.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
>
> diff --git a/tools/xenlogd/io.c b/tools/xenlogd/io.c
> index 6e92667fab..6b4692ca67 100644
> --- a/tools/xenlogd/io.c
> +++ b/tools/xenlogd/io.c

> @@ -1010,6 +1011,51 @@ static void p9_create(device *device, struct p9_header *hdr)
>      fill_buffer(device, hdr->cmd + 1, hdr->tag, "QU", &qid, &iounit);
>  }
>
> +static void p9_write(device *device, struct p9_header *hdr)
> +{
> +    uint32_t fid;
> +    uint64_t off;
> +    unsigned int len;
> +    uint32_t written;
> +    void *buf;
> +    struct p9_fid *fidp;
> +    int ret;
> +
> +    ret = fill_data(device, "ULD", &fid, &off, &len, device->buffer);
> +    if ( ret != 3 )
> +    {
> +        p9_error(device, hdr->tag, EINVAL);
> +        return;
> +    }
> +
> +    fidp = find_fid(device, fid);
> +    if ( !fidp || !fidp->opened || fidp->isdir )

I think you want an additional check that the fidp is writable.

Regards,
Jason
Re: [PATCH 13/29] tools/xenlogd: add 9pfs write request support
Posted by Juergen Gross 2 years, 3 months ago
On 07.11.23 15:10, Jason Andryuk wrote:
> On Wed, Nov 1, 2023 at 5:54 AM Juergen Gross <jgross@suse.com> wrote:
>>
>> Add the write request of the 9pfs protocol.
>>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
>> ---
>>   tools/xenlogd/io.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 50 insertions(+)
>>
>> diff --git a/tools/xenlogd/io.c b/tools/xenlogd/io.c
>> index 6e92667fab..6b4692ca67 100644
>> --- a/tools/xenlogd/io.c
>> +++ b/tools/xenlogd/io.c
> 
>> @@ -1010,6 +1011,51 @@ static void p9_create(device *device, struct p9_header *hdr)
>>       fill_buffer(device, hdr->cmd + 1, hdr->tag, "QU", &qid, &iounit);
>>   }
>>
>> +static void p9_write(device *device, struct p9_header *hdr)
>> +{
>> +    uint32_t fid;
>> +    uint64_t off;
>> +    unsigned int len;
>> +    uint32_t written;
>> +    void *buf;
>> +    struct p9_fid *fidp;
>> +    int ret;
>> +
>> +    ret = fill_data(device, "ULD", &fid, &off, &len, device->buffer);
>> +    if ( ret != 3 )
>> +    {
>> +        p9_error(device, hdr->tag, EINVAL);
>> +        return;
>> +    }
>> +
>> +    fidp = find_fid(device, fid);
>> +    if ( !fidp || !fidp->opened || fidp->isdir )
> 
> I think you want an additional check that the fidp is writable.

The open was done with the correct mode. If fidp isn't writable, the write()
will fail with the correct errno.


Juergen

Re: [PATCH 13/29] tools/xenlogd: add 9pfs write request support
Posted by Jason Andryuk 2 years, 3 months ago
On Tue, Nov 7, 2023 at 9:43 AM Juergen Gross <jgross@suse.com> wrote:
>
> On 07.11.23 15:10, Jason Andryuk wrote:
> > On Wed, Nov 1, 2023 at 5:54 AM Juergen Gross <jgross@suse.com> wrote:
> >>
> >> Add the write request of the 9pfs protocol.
> >>
> >> Signed-off-by: Juergen Gross <jgross@suse.com>
> >> ---
> >>   tools/xenlogd/io.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++
> >>   1 file changed, 50 insertions(+)
> >>
> >> diff --git a/tools/xenlogd/io.c b/tools/xenlogd/io.c
> >> index 6e92667fab..6b4692ca67 100644
> >> --- a/tools/xenlogd/io.c
> >> +++ b/tools/xenlogd/io.c
> >
> >> @@ -1010,6 +1011,51 @@ static void p9_create(device *device, struct p9_header *hdr)
> >>       fill_buffer(device, hdr->cmd + 1, hdr->tag, "QU", &qid, &iounit);
> >>   }
> >>
> >> +static void p9_write(device *device, struct p9_header *hdr)
> >> +{
> >> +    uint32_t fid;
> >> +    uint64_t off;
> >> +    unsigned int len;
> >> +    uint32_t written;
> >> +    void *buf;
> >> +    struct p9_fid *fidp;
> >> +    int ret;
> >> +
> >> +    ret = fill_data(device, "ULD", &fid, &off, &len, device->buffer);
> >> +    if ( ret != 3 )
> >> +    {
> >> +        p9_error(device, hdr->tag, EINVAL);
> >> +        return;
> >> +    }
> >> +
> >> +    fidp = find_fid(device, fid);
> >> +    if ( !fidp || !fidp->opened || fidp->isdir )
> >
> > I think you want an additional check that the fidp is writable.
>
> The open was done with the correct mode. If fidp isn't writable, the write()
> will fail with the correct errno.

Oh, right.

Reviewed-by: Jason Andryuk <jandryuk@gmail.com>