All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] 9pfs-local: the security models enum?
@ 2015-03-04 21:17 Michael Tokarev
  0 siblings, 0 replies; only message in thread
From: Michael Tokarev @ 2015-03-04 21:17 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: qemu-devel, Anthony Liguori

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-03-04 21:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-04 21:17 [Qemu-devel] 9pfs-local: the security models enum? Michael Tokarev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.