mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-23 20:02:21 +00:00
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.
This commit is contained in:
parent
a01d93579e
commit
ae26731e1f
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user