2011-08-08 20:03:48 +02:00
|
|
|
/*
|
2016-06-06 11:52:34 +02:00
|
|
|
* 9p backend
|
2011-08-08 20:03:48 +02:00
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2011
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:10 +01:00
|
|
|
#include "qemu/osdep.h"
|
2011-08-08 20:03:48 +02:00
|
|
|
#include "fsdev/qemu-fsdev.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/thread.h"
|
2015-09-01 15:48:02 +02:00
|
|
|
#include "qemu/coroutine.h"
|
2015-11-18 18:57:30 +01:00
|
|
|
#include "coth.h"
|
2011-08-08 20:03:48 +02:00
|
|
|
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 18:36:19 +01:00
|
|
|
static ssize_t __readlink(V9fsState *s, V9fsPath *path, V9fsString *buf)
|
|
|
|
{
|
|
|
|
ssize_t len, maxlen = PATH_MAX;
|
|
|
|
|
|
|
|
buf->data = g_malloc(PATH_MAX);
|
|
|
|
for(;;) {
|
|
|
|
len = s->ops->readlink(&s->ctx, path, buf->data, maxlen);
|
|
|
|
if (len < 0) {
|
|
|
|
g_free(buf->data);
|
|
|
|
buf->data = NULL;
|
|
|
|
buf->size = 0;
|
|
|
|
break;
|
|
|
|
} else if (len == maxlen) {
|
|
|
|
/*
|
|
|
|
* We dodn't have space to put the NULL or we have more
|
|
|
|
* to read. Increase the size and try again
|
|
|
|
*/
|
|
|
|
maxlen *= 2;
|
|
|
|
g_free(buf->data);
|
|
|
|
buf->data = g_malloc(maxlen);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Null terminate the readlink output
|
|
|
|
*/
|
|
|
|
buf->data[len] = '\0';
|
|
|
|
buf->size = len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_readlink(V9fsPDU *pdu, V9fsPath *path, V9fsString *buf)
|
2011-08-08 20:03:48 +02:00
|
|
|
{
|
|
|
|
int err;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-08-08 20:03:48 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_read_lock(s);
|
2011-08-08 20:03:48 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 18:36:19 +01:00
|
|
|
err = __readlink(s, path, buf);
|
|
|
|
if (err < 0) {
|
2011-08-08 20:03:48 +02:00
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
});
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_unlock(s);
|
2011-08-08 20:03:48 +02:00
|
|
|
return err;
|
|
|
|
}
|
2011-05-19 01:03:49 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_statfs(V9fsPDU *pdu, V9fsPath *path, struct statfs *stbuf)
|
2011-05-19 01:03:49 +02:00
|
|
|
{
|
|
|
|
int err;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-05-19 01:03:49 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_read_lock(s);
|
2011-05-19 01:03:49 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
2011-09-09 11:44:18 +02:00
|
|
|
err = s->ops->statfs(&s->ctx, path, stbuf);
|
2011-05-19 01:03:49 +02:00
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
});
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_unlock(s);
|
2011-05-19 01:03:49 +02:00
|
|
|
return err;
|
|
|
|
}
|
2011-05-19 01:04:58 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_chmod(V9fsPDU *pdu, V9fsPath *path, mode_t mode)
|
2011-05-19 01:04:58 +02:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
FsCred cred;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-05-19 01:04:58 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-05-19 01:04:58 +02:00
|
|
|
cred_init(&cred);
|
|
|
|
cred.fc_mode = mode;
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_read_lock(s);
|
2011-05-19 01:04:58 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
2011-09-09 11:44:18 +02:00
|
|
|
err = s->ops->chmod(&s->ctx, path, &cred);
|
2011-05-19 01:04:58 +02:00
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
});
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_unlock(s);
|
2011-05-19 01:04:58 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_utimensat(V9fsPDU *pdu, V9fsPath *path,
|
2011-05-19 01:04:58 +02:00
|
|
|
struct timespec times[2])
|
|
|
|
{
|
|
|
|
int err;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-05-19 01:04:58 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_read_lock(s);
|
2011-05-19 01:04:58 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
2011-09-09 11:44:18 +02:00
|
|
|
err = s->ops->utimensat(&s->ctx, path, times);
|
2011-05-19 01:04:58 +02:00
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
});
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_unlock(s);
|
2011-05-19 01:04:58 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_chown(V9fsPDU *pdu, V9fsPath *path, uid_t uid, gid_t gid)
|
2011-05-19 01:04:58 +02:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
FsCred cred;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-05-19 01:04:58 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-05-19 01:04:58 +02:00
|
|
|
cred_init(&cred);
|
|
|
|
cred.fc_uid = uid;
|
|
|
|
cred.fc_gid = gid;
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_read_lock(s);
|
2011-05-19 01:04:58 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
2011-09-09 11:44:18 +02:00
|
|
|
err = s->ops->chown(&s->ctx, path, &cred);
|
2011-05-19 01:04:58 +02:00
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
});
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_unlock(s);
|
2011-05-19 01:04:58 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_truncate(V9fsPDU *pdu, V9fsPath *path, off_t size)
|
2011-05-19 01:04:58 +02:00
|
|
|
{
|
|
|
|
int err;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-05-19 01:04:58 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_read_lock(s);
|
2011-05-19 01:04:58 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
2011-09-09 11:44:18 +02:00
|
|
|
err = s->ops->truncate(&s->ctx, path, size);
|
2011-05-19 01:04:58 +02:00
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
});
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_unlock(s);
|
2011-05-19 01:04:58 +02:00
|
|
|
return err;
|
|
|
|
}
|
2011-05-19 01:06:38 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_mknod(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, uid_t uid,
|
2011-05-24 11:40:56 +02:00
|
|
|
gid_t gid, dev_t dev, mode_t mode, struct stat *stbuf)
|
2011-05-19 01:06:38 +02:00
|
|
|
{
|
|
|
|
int err;
|
2011-09-09 11:44:18 +02:00
|
|
|
V9fsPath path;
|
2011-05-19 01:06:38 +02:00
|
|
|
FsCred cred;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-05-19 01:06:38 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-05-19 01:06:38 +02:00
|
|
|
cred_init(&cred);
|
|
|
|
cred.fc_uid = uid;
|
|
|
|
cred.fc_gid = gid;
|
|
|
|
cred.fc_mode = mode;
|
|
|
|
cred.fc_rdev = dev;
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_read_lock(s);
|
2011-05-19 01:06:38 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
2011-09-09 11:44:18 +02:00
|
|
|
err = s->ops->mknod(&s->ctx, &fidp->path, name->data, &cred);
|
2011-05-19 01:06:38 +02:00
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
2011-05-24 11:40:56 +02:00
|
|
|
} else {
|
2011-09-09 11:44:18 +02:00
|
|
|
v9fs_path_init(&path);
|
|
|
|
err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
|
|
|
|
if (!err) {
|
|
|
|
err = s->ops->lstat(&s->ctx, &path, stbuf);
|
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
2011-05-24 11:40:56 +02:00
|
|
|
}
|
2011-09-09 11:44:18 +02:00
|
|
|
v9fs_path_free(&path);
|
2011-05-19 01:06:38 +02:00
|
|
|
}
|
|
|
|
});
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_unlock(s);
|
2011-05-19 01:06:38 +02:00
|
|
|
return err;
|
|
|
|
}
|
2011-08-08 20:18:29 +02:00
|
|
|
|
2011-09-09 11:44:18 +02:00
|
|
|
/* Only works with path name based fid */
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_remove(V9fsPDU *pdu, V9fsPath *path)
|
2011-08-08 20:18:29 +02:00
|
|
|
{
|
|
|
|
int err;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-08-08 20:18:29 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_read_lock(s);
|
2011-08-08 20:18:29 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
|
|
|
err = s->ops->remove(&s->ctx, path->data);
|
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
});
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_unlock(s);
|
2011-08-08 20:18:29 +02:00
|
|
|
return err;
|
|
|
|
}
|
2011-05-07 12:39:10 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_unlinkat(V9fsPDU *pdu, V9fsPath *path, V9fsString *name, int flags)
|
2011-09-09 11:44:18 +02:00
|
|
|
{
|
|
|
|
int err;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-09-09 11:44:18 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_read_lock(s);
|
2011-09-09 11:44:18 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
|
|
|
err = s->ops->unlinkat(&s->ctx, path, name->data, flags);
|
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
});
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_unlock(s);
|
2011-09-09 11:44:18 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only work with path name based fid */
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_rename(V9fsPDU *pdu, V9fsPath *oldpath, V9fsPath *newpath)
|
2011-05-07 12:39:10 +02:00
|
|
|
{
|
|
|
|
int err;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-05-07 12:39:10 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-05-07 12:39:10 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
|
|
|
err = s->ops->rename(&s->ctx, oldpath->data, newpath->data);
|
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return err;
|
|
|
|
}
|
2011-08-08 20:28:39 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_renameat(V9fsPDU *pdu, V9fsPath *olddirpath, V9fsString *oldname,
|
2011-09-09 11:44:18 +02:00
|
|
|
V9fsPath *newdirpath, V9fsString *newname)
|
|
|
|
{
|
|
|
|
int err;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-09-09 11:44:18 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-09-09 11:44:18 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
|
|
|
err = s->ops->renameat(&s->ctx, olddirpath, oldname->data,
|
|
|
|
newdirpath, newname->data);
|
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_symlink(V9fsPDU *pdu, V9fsFidState *dfidp, V9fsString *name,
|
2011-05-24 11:40:56 +02:00
|
|
|
const char *oldpath, gid_t gid, struct stat *stbuf)
|
2011-08-08 20:28:39 +02:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
FsCred cred;
|
2011-09-09 11:44:18 +02:00
|
|
|
V9fsPath path;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-05-24 11:40:56 +02:00
|
|
|
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-08-08 20:28:39 +02:00
|
|
|
cred_init(&cred);
|
2011-05-24 11:40:56 +02:00
|
|
|
cred.fc_uid = dfidp->uid;
|
2011-08-08 20:28:39 +02:00
|
|
|
cred.fc_gid = gid;
|
|
|
|
cred.fc_mode = 0777;
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_read_lock(s);
|
2011-08-08 20:28:39 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
2011-09-09 11:44:18 +02:00
|
|
|
err = s->ops->symlink(&s->ctx, oldpath, &dfidp->path,
|
|
|
|
name->data, &cred);
|
2011-08-08 20:28:39 +02:00
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
2011-05-24 11:40:56 +02:00
|
|
|
} else {
|
2011-09-09 11:44:18 +02:00
|
|
|
v9fs_path_init(&path);
|
|
|
|
err = v9fs_name_to_path(s, &dfidp->path, name->data, &path);
|
|
|
|
if (!err) {
|
|
|
|
err = s->ops->lstat(&s->ctx, &path, stbuf);
|
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
2011-05-24 11:40:56 +02:00
|
|
|
}
|
2011-09-09 11:44:18 +02:00
|
|
|
v9fs_path_free(&path);
|
2011-08-08 20:28:39 +02:00
|
|
|
}
|
|
|
|
});
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_path_unlock(s);
|
2011-09-09 11:44:18 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For path name based fid we don't block. So we can
|
|
|
|
* directly call the fs driver ops.
|
|
|
|
*/
|
2011-08-02 08:06:17 +02:00
|
|
|
int v9fs_co_name_to_path(V9fsPDU *pdu, V9fsPath *dirpath,
|
2011-09-09 11:44:18 +02:00
|
|
|
const char *name, V9fsPath *path)
|
|
|
|
{
|
|
|
|
int err;
|
2011-08-02 08:06:17 +02:00
|
|
|
V9fsState *s = pdu->s;
|
2011-08-02 08:05:54 +02:00
|
|
|
|
2011-10-12 17:29:18 +02:00
|
|
|
if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
|
2011-08-02 08:05:54 +02:00
|
|
|
err = s->ops->name_to_path(&s->ctx, dirpath, name, path);
|
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
} else {
|
2011-08-02 08:06:17 +02:00
|
|
|
if (v9fs_request_cancelled(pdu)) {
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2011-08-02 08:05:54 +02:00
|
|
|
v9fs_co_run_in_worker(
|
|
|
|
{
|
|
|
|
err = s->ops->name_to_path(&s->ctx, dirpath, name, path);
|
|
|
|
if (err < 0) {
|
|
|
|
err = -errno;
|
|
|
|
}
|
|
|
|
});
|
2011-09-09 11:44:18 +02:00
|
|
|
}
|
2011-08-08 20:28:39 +02:00
|
|
|
return err;
|
|
|
|
}
|