Commit Graph

31 Commits

Author SHA1 Message Date
Hidetoshi Seto 3867142346 virtio-9p: fix build on !CONFIG_UTIMENSAT
This patch introduce a fallback mechanism for old systems that do not
support utimensat().  This fix build failure with following warnings:

hw/virtio-9p-local.c: In function 'local_utimensat':
hw/virtio-9p-local.c:479: warning: implicit declaration of function 'utimensat'
hw/virtio-9p-local.c:479: warning: nested extern declaration of 'utimensat'

and:

hw/virtio-9p.c: In function 'v9fs_setattr_post_chmod':
hw/virtio-9p.c:1410: error: 'UTIME_NOW' undeclared (first use in this function)
hw/virtio-9p.c:1410: error: (Each undeclared identifier is reported only once
hw/virtio-9p.c:1410: error: for each function it appears in.)
hw/virtio-9p.c:1413: error: 'UTIME_OMIT' undeclared (first use in this function)
hw/virtio-9p.c: In function 'v9fs_wstat_post_chmod':
hw/virtio-9p.c:2905: error: 'UTIME_OMIT' undeclared (first use in this function)

[NOTE: At this time virtio-9p is only user of utimensat(), and is available
       only when host is linux and CONFIG_VIRTFS is defined.  So there are
       no similar warning for win32.  Please provide a wrapper for win32 in
       oslib-win32.c if new user really requires it.]

v5:
  - Allow fallback on runtime
  - Move qemu_utimensat() to oslib-posix.c
  - Rebased on latest qemu.git
v4:
  - Use tv_now.tv_usec
v3:
  - Use better alternative handling for UTIME_NOW/OMIT
  - Move qemu_utimensat() to cutils.c
V2:
  - Introduce qemu_utimensat()

Acked-by: Chris Wright <chrisw@sous-sol.org>
Acked-by: M. Mohan Kumar <mohan@in.ibm.com>
Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
2010-12-02 16:08:40 -08:00
Venkateswararao Jujjuri (JV) 49594973fb [virtio-9p] Add datasync to server side TFSYNC/RFSYNC for dotl
SYNOPSIS
    size[4] Tfsync tag[2] fid[4] datasync[4]

    size[4] Rfsync tag[2]

DESCRIPTION

    The Tfsync transaction transfers ("flushes") all modified in-core data of
    file identified by fid to the disk device (or other  permanent  storage
    device)  where that  file  resides.

    If datasync flag is specified data will be fleshed but does not flush
    modified metadata unless  that  metadata  is  needed  in order to allow a
    subsequent data retrieval to be correctly handled.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
2010-12-02 16:06:47 -08:00
Sanchit Garg 56d15a5329 [virtio-9p] Use preadv/pwritev instead of readv/writev
readv & writev, read & write respectively from the current offset
of the file & hence their use has to be preceeded by a call to lseek.
preadv/writev can be used instead, as they take the offset as an argument.
This saves one system call( lseek ).
In case preadv is not supported, it is implemented by an lseek
followed by a readv. Depending upon the configuration of QEMU, the
appropriate read & write methods are selected. This patch also fixes the
zero byte read/write bug & obviates the need to apply a fix for that bug separately.

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Sanchit Garg <sancgarg@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
2010-10-20 12:10:59 -05:00
Aneesh Kumar K.V fc22118d9b virtio-9p: Use layered xattr approach
We would need this to make sure we handle the mapped
security model correctly for different xattr names.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
2010-10-20 12:10:58 -05:00
Aneesh Kumar K.V 9ed3ef26e6 virtio-9p: Add support for removing xattr
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2010-09-08 22:56:42 +05:30
Aneesh Kumar K.V 5c0f255dd4 virtio-9p: Use lchown which won't follow symlink
We should always use functions which don't follow
symlink on the server

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2010-09-08 22:56:42 +05:30
Aneesh Kumar K.V 12848bfc5d virtio-9p: Add SM_NONE security model
This is equivalent to SM_PASSTHROUGH security model.
The only exception is, failure of privilige operation like chown
are ignored. This makes a passthrough like security model usable
for people who runs kvm as non root

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2010-09-08 22:56:42 +05:30
Aneesh Kumar K.V 61b6c4994a virtio-9p: Hide user.virtfs xattr in case of mapped security.
With mapped security mode we use "user.virtfs" namespace is used
to store the virtFs related attributes. So hide it from user.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2010-09-08 22:56:42 +05:30
Aneesh Kumar K.V 10b468bdc5 virtio-9p: Implement TXATTRCREATE
TXATTRCREATE:  Prepare a fid for setting xattr value on a file system object.

 size[4] TXATTRCREATE tag[2] fid[4] name[s] attr_size[8] flags[4]
 size[4] RXATTRWALK tag[2]

txattrcreate gets a fid pointing to xattr. This fid can later be
used to get set the xattr value.

flag value is derived from set Linux setxattr. The manpage says
"The flags parameter can be used to refine the semantics of the operation.
XATTR_CREATE specifies a pure create, which fails if the named attribute
exists already. XATTR_REPLACE specifies a pure replace operation, which
fails if the named attribute does not already exist. By default (no flags),
the extended attribute will be created if need be, or will simply replace
the value if the attribute exists."

The actual setxattr operation happens when the fid is clunked. At that point
the written byte count and the attr_size specified in TXATTRCREATE should be
same otherwise an error will be returned.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2010-09-08 22:56:41 +05:30
Aneesh Kumar K.V fa32ef8879 virtio-9p: Implement TXATTRWALK
TXATTRWALK: Descend a ATTR namespace

 size[4] TXATTRWALK tag[2] fid[4] newfid[4] name[s]
 size[4] RXATTRWALK tag[2] size[8]

txattrwalk gets a fid pointing to xattr. This fid can later be
used to get read the xattr value. If name is NULL the fid returned
can be used to get the list of extended attribute associated to
the file system object.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2010-09-08 22:56:41 +05:30
Sripathi Kodi c79ce73747 virtio-9p: Implement server side of setattr for 9P2000.L protocol.
SYNOPSIS

      size[4] Tsetattr tag[2] attr[n]

      size[4] Rsetattr tag[2]

   DESCRIPTION

      The setattr command changes some of the file status information.
      attr resembles the iattr structure used in Linux kernel. It
      specifies which status parameter is to be changed and to what
      value. It is laid out as follows:

         valid[4]
            specifies which status information is to be changed. Possible
            values are:
            ATTR_MODE       (1 << 0)
            ATTR_UID        (1 << 1)
            ATTR_GID        (1 << 2)
            ATTR_SIZE       (1 << 3)
            ATTR_ATIME      (1 << 4)
            ATTR_MTIME      (1 << 5)
            ATTR_CTIME      (1 << 5)
            ATTR_ATIME_SET  (1 << 7)
            ATTR_MTIME_SET  (1 << 8)

            The last two bits represent whether the time information
            is being sent by the client's user space. In the absense
            of these bits the server always uses server's time.

         mode[4]
            File permission bits

         uid[4]
            Owner id of file

         gid[4]
            Group id of the file

         size[8]
            File size

         atime_sec[8]
            Time of last file access, seconds

         atime_nsec[8]
            Time of last file access, nanoseconds

         mtime_sec[8]
            Time of last file modification, seconds

         mtime_nsec[8]
            Time of last file modification, nanoseconds

Explanation of the patches:
--------------------------

*) The kernel just copies relevent contents of iattr structure to p9_iattr_dotl
   structure and passes it down to the client. The only check it has is calling
   inode_change_ok()
*) The p9_iattr_dotl structure does not have ctime and ia_file parameters because
   I don't think these are needed in our case. The client user space can request
   updating just ctime by calling chown(fd, -1, -1). This is handled on server
   side without a need for putting ctime on the wire.
*) The server currently supports changing mode, time, ownership and size of the
   file.
*) 9P RFC says "Either all the changes in wstat request happen, or none of them
   does: if the request succeeds, all changes were made; if it fails, none were."
   I have not done anything to implement this specifically because I don't see
   a reason.

[jvrao@linux.vnet.ibm.com: Parts of code for handling chown(-1,-1)

Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
2010-09-08 22:56:40 +05:30
M. Mohan Kumar 74bc02b2d2 virtio-9p: Do not reset atime
Current code resets file's atime to 0 when there is a change in mtime.
    This results in resetting the atime to "1970-01-01 05:30:00". For
    example, truncate -s 0 filename results in changing the mtime to the
    truncate time, but resets the atime to "1970-01-01 05:30:00". utime
    system call does not have any provision to set only mtime or atime. So
    change v9fs_wstat_post_chmod function to use utimensat function to change
    the atime and mtime fields. If tv_nsec field is set to the special value
    "UTIME_OMIT", corresponding file time stamp is not updated.

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
2010-09-08 22:56:39 +05:30
M. Mohan Kumar be940c8716 qemu: virtio-9p: Implement statfs support in server
Implement statfs support in qemu server based on Sripathi's
initial statfs patch.

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
2010-09-08 22:56:39 +05:30
Blue Swirl f143efa60c Remove useless NULL check for qemu_strdup return value
Found with this Coccinelle semantic patch:
@@
expression E;
identifier ptr;
identifier fn ~= "qemu_strn?dup";
@@

-ptr = fn(E);
-if (ptr == NULL) { ... }
-
+ptr = fn(E);

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-08-19 20:24:43 +00:00
Venkateswararao Jujjuri (JV) 63729c3692 virtio-9p: Implement Security model for mksock using mknod.
This patch uses mknod to create socket.

On Host/Fileserver:
-rw-------. 1 virfsuid virtfsgid 0 2010-05-11 09:57 asocket1

On Guest/Client:
srwxr-xr-x 1 guestuser guestuser 0 2010-05-11 12:57 asocket1

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-06-22 15:15:51 -05:00
Venkateswararao Jujjuri (JV) 1c29331248 virtio-9p: Implement Security model for mknod
Mapped mode stores extended attributes in the user space of the extended
attributes. Given that the user space extended attributes are available
to regular files only, special files are created as regular files on the
fileserver and appropriate mode bits are added to the extended attributes.
This method presents all special files and symlinks as regular files on the
fileserver while they are represented as special files on the guest mount.

On Host/Fileserver:
-rw-------. 1 virfsuid virtfsgid 0 2010-05-11 09:36 afifo
-rw-------. 1 virfsuid virtfsgid 0 2010-05-11 09:32 blkdev
-rw-------. 1 virfsuid virtfsgid 0 2010-05-11 09:33 chardev

On Guest/Client:
prw-r--r-- 1 guestuser guestuser 0 2010-05-11 12:36 afifo
brw-r--r-- 1 guestuser guestuser 0, 0 2010-05-11 12:32 blkdev
crw-r--r-- 1 guestuser guestuser 4, 5 2010-05-11 12:33 chardev

In the passthrough securit model, specifal files are directly created
on the fileserver. But the user credential

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-06-22 15:15:51 -05:00
Venkateswararao Jujjuri (JV) 879c28133d virtio-9p: Security model for symlink and readlink
Mapped mode stores extended attributes in the user space of the extended
attributes. Given that the user space extended attributes are available
to regular files only, special files are created as regular files on the
fileserver and appropriate mode bits are added to the extended attributes.
This method presents all special files and symlinks as regular files on the
fileserver while they are represented as special files on the guest mount.

Implemntation of symlink in mapped security model:

A regular file is created and the link target is written to it.
readlink() reads it back from the file.

On Guest/Client:
lrwxrwxrwx 1 root root 6 2010-05-11 12:20 asymlink -> afile

On Host/Fileserver:
-rw-------. 1 root root 6 2010-05-11 09:20 asymlink
afile

Under passthrough model, it just calls underlying symlink() readlink()
system calls are used.

Under both security models, client user credentials are changed
after the filesystem objec creation.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-06-22 15:15:51 -05:00
Venkateswararao Jujjuri (JV) 00ec5c3760 virtio-9p: Security model for mkdir
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-06-22 15:15:51 -05:00
Venkateswararao Jujjuri (JV) 4750a96f6b virtio-9p: Security model for create/open2
In the mapped security model, VirtFS server intercepts and maps
the file object create and get/set attribute requests. Files on the fileserver
will be created with VirtFS servers (QEMU) user credentials and the
client-users credentials are stored in extended attributes. On the request
to get attributes, server extracts the client-users credentials
from extended attributes and sends them to the client.

On Host/Fileserver:
-rw-------. 2 virfsuid virtfsgid 0 2010-05-11 09:19 afile

On Guest/Client:
-rw-r--r-- 2 guestuser guestuser 0 2010-05-11 12:19 afile

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-06-22 15:15:50 -05:00
Venkateswararao Jujjuri (JV) 1237ad7607 virtio-9p: Implemented Security model for lstat and fstat
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-06-22 15:15:50 -05:00
Venkateswararao Jujjuri (JV) f7613bee32 virtio-9p: Security model for chown
mapped model changes the owner in the extended attributes.
passthrough model does the change through lchown() as the
server don't need to follow the link and client will send the
actual filesystem object.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-06-22 15:15:50 -05:00
Venkateswararao Jujjuri (JV) e95ead32ef virtio-9p: Security model for chmod
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-06-22 15:15:50 -05:00
Venkateswararao Jujjuri (JV) 758e8e38eb virtio-9p: Make infrastructure for the new security model.
This patch adds required infrastructure for the new security model.

- A new configure option for attr/xattr.
- if CONFIG_VIRTFS will be defined if both CONFIG_LINUX and CONFIG_ATTR defined.
- Defines routines related to both security models.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-06-22 15:15:50 -05:00
Anthony Liguori 5bae190082 virtio-9p: Add P9_TREMOVE support.
Implement P9_TREMOVE support.
This gets file deletion to work.

[mohan@in.ibm.com: Fix truncate to use the relative path]

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-05-03 12:17:39 -05:00
Anthony Liguori 8cf89e007a virtio-9p: Add P9_TWSTAT support
Implement P9_TWSTAT support.
This gets file and directory creation to work.

[jvrao@linux.vnet.ibm.com: strdup to qemu_strdup conversion]
[aneesh.kumar@linux.vnet.ibm.com: v9fs_fix_path]

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-05-03 12:17:39 -05:00
Anthony Liguori c494dd6f28 virtio-9p: Add P9_TCREATE support
Implement P9_TCREATE support.
[jvrao@linux.vnet.ibm.com: strdup to qemu_strdup conversion]

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-05-03 12:17:39 -05:00
Anthony Liguori 8449360cbd virtio-9p: Add P9_TWRITE support
Implement P9_TWRITE support.
This gets write to file to work

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-05-03 12:17:39 -05:00
Anthony Liguori a92315553d virtio-9p: Add P9_TREAD support
Implement P9_TREAD support.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-05-03 12:17:39 -05:00
Anthony Liguori a6568fe27f virtio-9p: Add P9_TOPEN support.
Implement P9_TOPEN support.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-05-03 12:17:39 -05:00
Anthony Liguori 131dcb2521 virtio-9p: Add minimal set of FileOperations
Add minimal set of FileOperations and the corresponding implementations for
local fstype. These will be required for the FID management patches later on.

[aneesh.kumar@linux.vnet.ibm.com: rpath fix ]
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-05-03 12:17:38 -05:00
Anthony Liguori 9f10751365 virtio-9p: Add a virtio 9p device to qemu
This patch doesn't implement the 9p protocol handling
code. It adds a simple device which dump the protocol data.

[jvrao@linux.vnet.ibm.com: Little-Endian to host format conversion]
[aneesh.kumar@linux.vnet.ibm.com: Multiple-mounts support]

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-05-03 12:17:37 -05:00