diff mbox series

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

Message ID 20231101093325.30302-14-jgross@suse.com (mailing list archive)
State Superseded
Headers show
Series tools: enable xenstore-stubdom to use 9pfs | expand

Commit Message

Jürgen Groß Nov. 1, 2023, 9:33 a.m. UTC
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(+)

Comments

Jason Andryuk Nov. 7, 2023, 2:10 p.m. UTC | #1
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
Jürgen Groß Nov. 7, 2023, 2:43 p.m. UTC | #2
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
Jason Andryuk Nov. 7, 2023, 3:21 p.m. UTC | #3
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>
diff mbox series

Patch

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;