qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH RFC 13/36] 9pfs: local: pre unlikat operation for ma


From: Greg Kurz
Subject: [Qemu-devel] [PATCH RFC 13/36] 9pfs: local: pre unlikat operation for mapped-file security
Date: Mon, 30 Jan 2017 13:11:16 +0100
User-agent: StGit/0.17.1-20-gc0b1b-dirty

The unlinkat 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 <address@hidden>
---
 hw/9pfs/9p-local.c |   68 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 24 deletions(-)

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 7506d2155c05..b75ad452decc 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -1462,39 +1462,23 @@ static int local_renameat(FsContext *ctx, V9fsPath 
*olddir,
     return ret;
 }
 
-static int local_unlinkat(FsContext *ctx, V9fsPath *dir,
-                          const char *name, int flags)
+static int local_pre_unlinkat_mapped_file(FsContext *ctx, V9fsPath *dir,
+                                          const char *name, int flags)
 {
     int ret;
     V9fsString fullname;
     char *buffer;
 
     v9fs_string_init(&fullname);
-
     v9fs_string_sprintf(&fullname, "%s/%s", dir->data, name);
-    if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
-        if (flags == AT_REMOVEDIR) {
-            /*
-             * If directory remove .virtfs_metadata contained in the
-             * directory
-             */
-            buffer = g_strdup_printf("%s/%s/%s", ctx->fs_root,
-                                     fullname.data, VIRTFS_META_DIR);
-            ret = remove(buffer);
-            g_free(buffer);
-            if (ret < 0 && errno != ENOENT) {
-                /*
-                 * We didn't had the .virtfs_metadata file. May be file created
-                 * in non-mapped mode ?. Ignore ENOENT.
-                 */
-                goto err_out;
-            }
-        }
+
+    if (flags == AT_REMOVEDIR) {
         /*
-         * Now remove the name from parent directory
-         * .virtfs_metadata directory.
+         * If directory remove .virtfs_metadata contained in the
+         * directory
          */
-        buffer = local_mapped_attr_path(ctx, fullname.data);
+        buffer = g_strdup_printf("%s/%s/%s", ctx->fs_root,
+                                 fullname.data, VIRTFS_META_DIR);
         ret = remove(buffer);
         g_free(buffer);
         if (ret < 0 && errno != ENOENT) {
@@ -1505,6 +1489,42 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir,
             goto err_out;
         }
     }
+    /*
+     * Now remove the name from parent directory
+     * .virtfs_metadata directory.
+     */
+    buffer = local_mapped_attr_path(ctx, fullname.data);
+    ret = remove(buffer);
+    g_free(buffer);
+    if (ret < 0 && errno == ENOENT) {
+        /*
+         * We didn't had the .virtfs_metadata file. May be file created
+         * in non-mapped mode ?. Ignore ENOENT.
+         */
+        ret = 0;
+    }
+
+err_out:
+    v9fs_string_free(&fullname);
+    return ret;
+}
+
+static int local_unlinkat(FsContext *ctx, V9fsPath *dir, const char *name,
+                          int flags)
+{
+    int ret;
+    V9fsString fullname;
+    char *buffer;
+
+    v9fs_string_init(&fullname);
+    v9fs_string_sprintf(&fullname, "%s/%s", dir->data, name);
+
+    if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
+        ret = local_pre_unlinkat_mapped_file(ctx, dir, name, flags);
+        if (ret < 0) {
+            goto err_out;
+        }
+    }
     /* Remove the name finally */
     buffer = rpath(ctx, fullname.data);
     ret = remove(buffer);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]