qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] 9pfs-local: the security models enum?


From: Michael Tokarev
Subject: [Qemu-devel] 9pfs-local: the security models enum?
Date: Thu, 05 Mar 2015 00:17:10 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.4.0

I noticed that most file operations in hw/9pfs/virtio-9p-local.c
are modelled like this:

    if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
       /* MAPPED version */
    } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
       /* MAPPED_FILE version */
    } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
               (fs_ctx->export_flags & V9FS_SM_NONE)) {
       /* PASSTHROUGH or NONE version */
    } else {
       /* this is my addition to show the "default" case */
       err = -1;
    }

I've 2 questions about this.

First, why we always have the "else" case, is it really
possible to have export_flags set in such a way so that
none of the 4 conditions are true?  If there's exactly
4 possible variants without the "else", it is possible
to simplify most of these functions greatly.

And second, why this code does not use a switch, why all
these ifs?  switch statement is good because the compiler
can check possible additional cases which are added later,
if that's the reason why we have this "else" to start with.
Something like this:

 switch (fs_ctx->export_flags & V9FS_SEC_MASK) {
   case V9FS_SM_MAPPED_FILE:
   ...
 }

(it is not that easy for the compiler to check this in
this form, so maybe security model should be moved from
export_flags to an additional field?)

Thanks,

/mjt



reply via email to

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