When using the mapped-file security model, we also have to create a link
for the metadata file if it exists. In case of failure, we should rollback.
That's what this patch does.
Signed-off-by: Greg Kurz <groug@kaod.org>
---
hw/9pfs/9p-local.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 15e746ede86a..9b9c39ee42ee 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -915,6 +915,7 @@ static int local_link(FsContext *ctx, V9fsPath *oldpath,
int ret;
V9fsString newpath;
char *buffer, *buffer1;
+ int serrno;
v9fs_string_init(&newpath);
v9fs_string_sprintf(&newpath, "%s/%s", dirpath->data, name);
@@ -923,25 +924,36 @@ static int local_link(FsContext *ctx, V9fsPath *oldpath,
buffer1 = rpath(ctx, newpath.data);
ret = link(buffer, buffer1);
g_free(buffer);
- g_free(buffer1);
+ if (ret < 0) {
+ goto out;
+ }
/* now link the virtfs_metadata files */
- if (!ret && (ctx->export_flags & V9FS_SM_MAPPED_FILE)) {
+ if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
+ char *vbuffer, *vbuffer1;
+
/* Link the .virtfs_metadata files. Create the metada directory */
ret = local_create_mapped_attr_dir(ctx, newpath.data);
if (ret < 0) {
goto err_out;
}
- buffer = local_mapped_attr_path(ctx, oldpath->data);
- buffer1 = local_mapped_attr_path(ctx, newpath.data);
- ret = link(buffer, buffer1);
- g_free(buffer);
- g_free(buffer1);
+ vbuffer = local_mapped_attr_path(ctx, oldpath->data);
+ vbuffer1 = local_mapped_attr_path(ctx, newpath.data);
+ ret = link(vbuffer, vbuffer1);
+ g_free(vbuffer);
+ g_free(vbuffer1);
if (ret < 0 && errno != ENOENT) {
goto err_out;
}
}
+ goto out;
+
err_out:
+ serrno = errno;
+ remove(buffer1);
+ errno = serrno;
+out:
+ g_free(buffer1);
v9fs_string_free(&newpath);
return ret;
}