Skip to content

Commit 771e9d4

Browse files
M. Mohan Kumarkvaneesh
M. Mohan Kumar
authored andcommitted
[virtio-9p] qemu: virtio-9p: Implement LOPEN
Implement 9p2000.L version of open(LOPEN) interface in qemu 9p server. For LOPEN, no need to convert the flags to and from 9p mode to VFS mode. Synopsis: size[4] Tlopen tag[2] fid[4] mode[4] size[4] Rlopen tag[2] qid[13] iounit[4] Current qemu 9p server does not support following flags: O_NOCTTY, O_NONBLOCK, O_ASYNC & O_CLOEXEC [Fix mode format - [email protected]] Signed-off-by: M. Mohan Kumar <[email protected]> Signed-off-by: Venkateswararao Jujjuri <[email protected]>
1 parent c7b4b0b commit 771e9d4

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

hw/virtio-9p.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,8 +1621,19 @@ static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err)
16211621
qemu_free(vs);
16221622
}
16231623

1624+
static inline int valid_flags(int flag)
1625+
{
1626+
if (flag & O_NOCTTY || flag & O_NONBLOCK || flag & O_ASYNC ||
1627+
flag & O_CLOEXEC)
1628+
return 0;
1629+
else
1630+
return 1;
1631+
}
1632+
16241633
static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
16251634
{
1635+
int flags;
1636+
16261637
if (err) {
16271638
err = -errno;
16281639
goto out;
@@ -1634,8 +1645,16 @@ static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
16341645
vs->fidp->dir = v9fs_do_opendir(s, &vs->fidp->path);
16351646
v9fs_open_post_opendir(s, vs, err);
16361647
} else {
1637-
vs->fidp->fd = v9fs_do_open(s, &vs->fidp->path,
1638-
omode_to_uflags(vs->mode));
1648+
if (s->proto_version == V9FS_PROTO_2000L) {
1649+
if (!valid_flags(vs->mode)) {
1650+
err = -EINVAL;
1651+
goto out;
1652+
}
1653+
flags = vs->mode;
1654+
} else {
1655+
flags = omode_to_uflags(vs->mode);
1656+
}
1657+
vs->fidp->fd = v9fs_do_open(s, &vs->fidp->path, flags);
16391658
v9fs_open_post_open(s, vs, err);
16401659
}
16411660
return;
@@ -1650,12 +1669,16 @@ static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
16501669
V9fsOpenState *vs;
16511670
ssize_t err = 0;
16521671

1653-
16541672
vs = qemu_malloc(sizeof(*vs));
16551673
vs->pdu = pdu;
16561674
vs->offset = 7;
1675+
vs->mode = 0;
16571676

1658-
pdu_unmarshal(vs->pdu, vs->offset, "db", &fid, &vs->mode);
1677+
if (s->proto_version == V9FS_PROTO_2000L) {
1678+
pdu_unmarshal(vs->pdu, vs->offset, "dd", &fid, &vs->mode);
1679+
} else {
1680+
pdu_unmarshal(vs->pdu, vs->offset, "db", &fid, &vs->mode);
1681+
}
16591682

16601683
vs->fidp = lookup_fid(s, fid);
16611684
if (vs->fidp == NULL) {
@@ -3076,6 +3099,7 @@ static pdu_handler_t *pdu_handlers[] = {
30763099
[P9_TRENAME] = v9fs_rename,
30773100
[P9_TMKDIR] = v9fs_mkdir,
30783101
[P9_TVERSION] = v9fs_version,
3102+
[P9_TLOPEN] = v9fs_open,
30793103
[P9_TATTACH] = v9fs_attach,
30803104
[P9_TSTAT] = v9fs_stat,
30813105
[P9_TWALK] = v9fs_walk,

hw/virtio-9p.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
enum {
1616
P9_TSTATFS = 8,
1717
P9_RSTATFS,
18+
P9_TLOPEN = 12,
19+
P9_RLOPEN,
1820
P9_TLCREATE = 14,
1921
P9_RLCREATE,
2022
P9_TSYMLINK = 16,
@@ -259,7 +261,7 @@ typedef struct V9fsWalkState {
259261
typedef struct V9fsOpenState {
260262
V9fsPDU *pdu;
261263
size_t offset;
262-
int8_t mode;
264+
int32_t mode;
263265
V9fsFidState *fidp;
264266
V9fsQID qid;
265267
struct stat stbuf;

0 commit comments

Comments
 (0)