提交 ae26731e 编写于 作者: P Peter Krempa

storage: Add support for access to files using provided uid/gid

To allow using the storage driver APIs to access files on various
storage sources in a universal fashion possibly on storage such as nfs
with root squash we'll need to store the desired uid/gid in the
metadata.

Add new initialisation API that will store the desired uid/gid and a
wrapper for the current use. Additionally add docs for the two APIs.
上级 a01d9357
......@@ -169,6 +169,9 @@ typedef virStorageFileBackend *virStorageFileBackendPtr;
struct _virStorageDriverData {
virStorageFileBackendPtr backend;
void *priv;
uid_t uid;
gid_t gid;
};
typedef int
......
......@@ -2801,13 +2801,37 @@ virStorageFileDeinit(virStorageSourcePtr src)
}
/**
* virStorageFileInitAs:
*
* @src: storage source definition
* @uid: uid used to access the file, or -1 for current uid
* @gid: gid used to access the file, or -1 for current gid
*
* Initialize a storage source to be used with storage driver. Use the provided
* uid and gid if possible for the operations.
*
* Returns 0 if the storage file was successfully initialized, -1 if the
* initialization failed. Libvirt error is reported.
*/
int
virStorageFileInit(virStorageSourcePtr src)
virStorageFileInitAs(virStorageSourcePtr src,
uid_t uid, gid_t gid)
{
int actualType = virStorageSourceGetActualType(src);
if (VIR_ALLOC(src->drv) < 0)
return -1;
if (uid == (uid_t) -1)
src->drv->uid = geteuid();
else
src->drv->uid = uid;
if (gid == (gid_t) -1)
src->drv->gid = getegid();
else
src->drv->gid = gid;
if (!(src->drv->backend = virStorageFileBackendForType(actualType,
src->protocol)))
goto error;
......@@ -2824,6 +2848,19 @@ virStorageFileInit(virStorageSourcePtr src)
}
/**
* virStorageFileInit:
*
* See virStorageFileInitAs. The file is initialized to be accessed by the
* current user.
*/
int
virStorageFileInit(virStorageSourcePtr src)
{
return virStorageFileInitAs(src, -1, -1);
}
/**
* virStorageFileCreate: Creates an empty storage file via storage driver
*
......
......@@ -29,8 +29,9 @@
# include "storage_conf.h"
# include "virstoragefile.h"
int
virStorageFileInit(virStorageSourcePtr src);
int virStorageFileInit(virStorageSourcePtr src);
int virStorageFileInitAs(virStorageSourcePtr src,
uid_t uid, gid_t gid);
void virStorageFileDeinit(virStorageSourcePtr src);
int virStorageFileCreate(virStorageSourcePtr src);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册