Skip to content

Commit 65603a8

Browse files
committed
fsdev: improve error handling of backend init
This patch changes some error messages in the backend init code and convert backends to propagate QEMU Error objects instead of calling error_report(). One notable improvement is that the local backend now provides a more detailed error report when it fails to open the shared directory. Signed-off-by: Greg Kurz <[email protected]>
1 parent 91cda4e commit 65603a8

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

fsdev/file-op-9p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void cred_init(FsCred *);
104104
struct FileOperations
105105
{
106106
int (*parse_opts)(QemuOpts *, FsDriverEntry *, Error **errp);
107-
int (*init)(FsContext *);
107+
int (*init)(FsContext *, Error **errp);
108108
void (*cleanup)(FsContext *);
109109
int (*lstat)(FsContext *, V9fsPath *, struct stat *);
110110
ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t);

hw/9pfs/9p-handle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ static int handle_ioc_getversion(FsContext *ctx, V9fsPath *path,
604604
#endif
605605
}
606606

607-
static int handle_init(FsContext *ctx)
607+
static int handle_init(FsContext *ctx, Error **errp)
608608
{
609609
int ret, mnt_id;
610610
struct statfs stbuf;

hw/9pfs/9p-local.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,13 +1400,14 @@ static int local_ioc_getversion(FsContext *ctx, V9fsPath *path,
14001400
#endif
14011401
}
14021402

1403-
static int local_init(FsContext *ctx)
1403+
static int local_init(FsContext *ctx, Error **errp)
14041404
{
14051405
struct statfs stbuf;
14061406
LocalData *data = g_malloc(sizeof(*data));
14071407

14081408
data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_RDONLY);
14091409
if (data->mountfd == -1) {
1410+
error_setg_errno(errp, errno, "failed to open '%s'", ctx->fs_root);
14101411
goto err;
14111412
}
14121413

hw/9pfs/9p-proxy.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,25 +1083,25 @@ static int proxy_ioc_getversion(FsContext *fs_ctx, V9fsPath *path,
10831083
return err;
10841084
}
10851085

1086-
static int connect_namedsocket(const char *path)
1086+
static int connect_namedsocket(const char *path, Error **errp)
10871087
{
10881088
int sockfd, size;
10891089
struct sockaddr_un helper;
10901090

10911091
if (strlen(path) >= sizeof(helper.sun_path)) {
1092-
error_report("Socket name too long");
1092+
error_setg(errp, "socket name too long");
10931093
return -1;
10941094
}
10951095
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
10961096
if (sockfd < 0) {
1097-
error_report("Failed to create socket: %s", strerror(errno));
1097+
error_setg_errno(errp, errno, "failed to create client socket");
10981098
return -1;
10991099
}
11001100
strcpy(helper.sun_path, path);
11011101
helper.sun_family = AF_UNIX;
11021102
size = strlen(helper.sun_path) + sizeof(helper.sun_family);
11031103
if (connect(sockfd, (struct sockaddr *)&helper, size) < 0) {
1104-
error_report("Failed to connect to %s: %s", path, strerror(errno));
1104+
error_setg_errno(errp, errno, "failed to connect to '%s'", path);
11051105
close(sockfd);
11061106
return -1;
11071107
}
@@ -1144,17 +1144,17 @@ static int proxy_parse_opts(QemuOpts *opts, FsDriverEntry *fs, Error **errp)
11441144
return 0;
11451145
}
11461146

1147-
static int proxy_init(FsContext *ctx)
1147+
static int proxy_init(FsContext *ctx, Error **errp)
11481148
{
11491149
V9fsProxy *proxy = g_malloc(sizeof(V9fsProxy));
11501150
int sock_id;
11511151

11521152
if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) {
1153-
sock_id = connect_namedsocket(ctx->fs_root);
1153+
sock_id = connect_namedsocket(ctx->fs_root, errp);
11541154
} else {
11551155
sock_id = atoi(ctx->fs_root);
11561156
if (sock_id < 0) {
1157-
error_report("Socket descriptor not initialized");
1157+
error_setg(errp, "socket descriptor not initialized");
11581158
}
11591159
}
11601160
if (sock_id < 0) {

hw/9pfs/9p-synth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ static int synth_unlinkat(FsContext *ctx, V9fsPath *dir,
514514
return -1;
515515
}
516516

517-
static int synth_init(FsContext *ctx)
517+
static int synth_init(FsContext *ctx, Error **errp)
518518
{
519519
QLIST_INIT(&synth_root.child);
520520
qemu_mutex_init(&synth_mutex);

hw/9pfs/9p.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,9 +3542,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp)
35423542
s->fid_list = NULL;
35433543
qemu_co_rwlock_init(&s->rename_lock);
35443544

3545-
if (s->ops->init(&s->ctx) < 0) {
3546-
error_setg(errp, "9pfs Failed to initialize fs-driver with id:%s"
3547-
" and export path:%s", s->fsconf.fsdev_id, s->ctx.fs_root);
3545+
if (s->ops->init(&s->ctx, errp) < 0) {
3546+
error_prepend(errp, "cannot initialize fsdev '%s': ",
3547+
s->fsconf.fsdev_id);
35483548
goto out;
35493549
}
35503550

0 commit comments

Comments
 (0)