The remove operation is really the same for the passthrough and mapped security models. This patch simply moves the mapped-file bits to a separate function. This will make future modifications easier.
This doesn't fix any bug, it is just preparatory cleanup. Signed-off-by: Greg Kurz <[email protected]> --- hw/9pfs/9p-local.c | 74 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 74953e4dbfe0..7506d2155c05 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1303,41 +1303,25 @@ static int local_utimensat(FsContext *s, V9fsPath *fs_path, return ret; } -static int local_remove(FsContext *ctx, const char *path) +static int local_pre_remove_mapped_file(FsContext *ctx, const char *path) { int err; struct stat stbuf; char *buffer; - if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { - buffer = rpath(ctx, path); - err = lstat(buffer, &stbuf); - g_free(buffer); - if (err) { - goto err_out; - } - /* - * If directory remove .virtfs_metadata contained in the - * directory - */ - if (S_ISDIR(stbuf.st_mode)) { - buffer = g_strdup_printf("%s/%s/%s", ctx->fs_root, - path, VIRTFS_META_DIR); - err = remove(buffer); - g_free(buffer); - if (err < 0 && errno != ENOENT) { - /* - * We didn't had the .virtfs_metadata file. May be file created - * in non-mapped mode ?. Ignore ENOENT. - */ - goto err_out; - } - } - /* - * Now remove the name from parent directory - * .virtfs_metadata directory - */ - buffer = local_mapped_attr_path(ctx, path); + buffer = rpath(ctx, path); + err = lstat(buffer, &stbuf); + g_free(buffer); + if (err) { + goto err_out; + } + /* + * If directory remove .virtfs_metadata contained in the + * directory + */ + if (S_ISDIR(stbuf.st_mode)) { + buffer = g_strdup_printf("%s/%s/%s", ctx->fs_root, + path, VIRTFS_META_DIR); err = remove(buffer); g_free(buffer); if (err < 0 && errno != ENOENT) { @@ -1348,6 +1332,36 @@ static int local_remove(FsContext *ctx, const char *path) goto err_out; } } + /* + * Now remove the name from parent directory + * .virtfs_metadata directory + */ + buffer = local_mapped_attr_path(ctx, path); + err = remove(buffer); + g_free(buffer); + if (err < 0 && errno == ENOENT) { + /* + * We didn't had the .virtfs_metadata file. May be file created + * in non-mapped mode ?. Ignore ENOENT. + */ + err = 0; + } + +err_out: + return err; +} + +static int local_remove(FsContext *ctx, const char *path) +{ + int err; + char *buffer; + + if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { + err = local_pre_remove_mapped_file(ctx, path); + if (err) { + goto err_out; + } + } buffer = rpath(ctx, path); err = remove(buffer);
