Skip to content

Commit

Permalink
vfs: add path parameter to get_quota
Browse files Browse the repository at this point in the history
Adding a path parameter would allow the VFS get_quota
function to be used for determining the quota/usage
when calculating size and free spacei.

Signed-off-by: Uri Simchoni <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
  • Loading branch information
urisimchoni authored and obnoxxx committed Jan 26, 2016
1 parent f71761c commit c464b9e
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 45 deletions.
5 changes: 3 additions & 2 deletions examples/VFS/skel_opaque.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ static uint64_t skel_disk_free(vfs_handle_struct *handle, const char *path,
return 0;
}

static int skel_get_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype,
unid_t id, SMB_DISK_QUOTA *dq)
static int skel_get_quota(vfs_handle_struct *handle, const char *path,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *dq)
{
errno = ENOSYS;
return -1;
Expand Down
7 changes: 4 additions & 3 deletions examples/VFS/skel_transparent.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ static uint64_t skel_disk_free(vfs_handle_struct *handle, const char *path,
return SMB_VFS_NEXT_DISK_FREE(handle, path, bsize, dfree, dsize);
}

static int skel_get_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype,
unid_t id, SMB_DISK_QUOTA *dq)
static int skel_get_quota(vfs_handle_struct *handle, const char *path,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *dq)
{
return SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, dq);
return SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, dq);
}

static int skel_set_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype,
Expand Down
6 changes: 4 additions & 2 deletions source3/include/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,9 @@ struct vfs_fn_pointers {
void (*disconnect_fn)(struct vfs_handle_struct *handle);
uint64_t (*disk_free_fn)(struct vfs_handle_struct *handle, const char *path, uint64_t *bsize,
uint64_t *dfree, uint64_t *dsize);
int (*get_quota_fn)(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt);
int (*get_quota_fn)(struct vfs_handle_struct *handle, const char *path,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *qt);
int (*set_quota_fn)(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt);
int (*get_shadow_copy_data_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, struct shadow_copy_data *shadow_copy_data, bool labels);
int (*statvfs_fn)(struct vfs_handle_struct *handle, const char *path, struct vfs_statvfs_struct *statbuf);
Expand Down Expand Up @@ -931,7 +933,7 @@ void smb_vfs_call_disconnect(struct vfs_handle_struct *handle);
uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle,
const char *path, uint64_t *bsize,
uint64_t *dfree, uint64_t *dsize);
int smb_vfs_call_get_quota(struct vfs_handle_struct *handle,
int smb_vfs_call_get_quota(struct vfs_handle_struct *handle, const char *path,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *qt);
int smb_vfs_call_set_quota(struct vfs_handle_struct *handle,
Expand Down
8 changes: 4 additions & 4 deletions source3/include/vfs_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
#define SMB_VFS_NEXT_DISK_FREE(handle, path, bsize, dfree ,dsize)\
smb_vfs_call_disk_free((handle)->next, (path), (bsize), (dfree), (dsize))

#define SMB_VFS_GET_QUOTA(conn, qtype, id, qt) \
smb_vfs_call_get_quota((conn)->vfs_handles, (qtype), (id), (qt))
#define SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt) \
smb_vfs_call_get_quota((handle)->next, (qtype), (id), (qt))
#define SMB_VFS_GET_QUOTA(conn, path, qtype, id, qt) \
smb_vfs_call_get_quota((conn)->vfs_handles, (path), (qtype), (id), (qt))
#define SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, qt) \
smb_vfs_call_get_quota((handle)->next, (path), (qtype), (id), (qt))

#define SMB_VFS_SET_QUOTA(conn, qtype, id, qt) \
smb_vfs_call_set_quota((conn)->vfs_handles, (qtype), (id), (qt))
Expand Down
4 changes: 3 additions & 1 deletion source3/modules/vfs_ceph.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ static uint64_t cephwrap_disk_free(struct vfs_handle_struct *handle,
}
}

static int cephwrap_get_quota(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
static int cephwrap_get_quota(struct vfs_handle_struct *handle,
const char *path, enum SMB_QUOTA_TYPE qtype,
unid_t id, SMB_DISK_QUOTA *qt)
{
/* libceph: Ceph does not implement this */
#if 0
Expand Down
6 changes: 4 additions & 2 deletions source3/modules/vfs_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ static uint64_t vfswrap_disk_free(vfs_handle_struct *handle, const char *path,
return result;
}

static int vfswrap_get_quota(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
static int vfswrap_get_quota(struct vfs_handle_struct *handle, const char *path,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *qt)
{
#ifdef HAVE_SYS_QUOTAS
int result;

START_PROFILE(syscall_get_quota);
result = sys_get_quota(handle->conn->connectpath, qtype, id, qt);
result = sys_get_quota(path, qtype, id, qt);
END_PROFILE(syscall_get_quota);
return result;
#else
Expand Down
13 changes: 9 additions & 4 deletions source3/modules/vfs_default_quota.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@
#define DEFAULT_QUOTA_GID_NOLIMIT(handle) \
lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid nolimit",DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT)

static int default_quota_get_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq)
static int default_quota_get_quota(vfs_handle_struct *handle, const char *path,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *dq)
{
int ret = -1;

if ((ret=SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, dq))!=0) {
if ((ret = SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, dq)) != 0) {
return ret;
}

Expand All @@ -122,7 +124,8 @@ static int default_quota_get_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYP
unid_t qid;
uint32_t qflags = dq->qflags;
qid.uid = DEFAULT_QUOTA_UID(handle);
SMB_VFS_NEXT_GET_QUOTA(handle, SMB_USER_QUOTA_TYPE, qid, dq);
SMB_VFS_NEXT_GET_QUOTA(
handle, path, SMB_USER_QUOTA_TYPE, qid, dq);
dq->qflags = qflags;
}
break;
Expand All @@ -132,7 +135,9 @@ static int default_quota_get_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYP
unid_t qid;
uint32_t qflags = dq->qflags;
qid.gid = DEFAULT_QUOTA_GID(handle);
SMB_VFS_NEXT_GET_QUOTA(handle, SMB_GROUP_QUOTA_TYPE, qid, dq);
SMB_VFS_NEXT_GET_QUOTA(handle, path,
SMB_GROUP_QUOTA_TYPE,
qid, dq);
dq->qflags = qflags;
}
break;
Expand Down
26 changes: 9 additions & 17 deletions source3/modules/vfs_fake_dfq.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_VFS

static int dfq_get_quota_do(struct vfs_handle_struct *handle, const char *path,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *qt);
static int dfq_get_quota(struct vfs_handle_struct *handle, const char *path,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *qt);

static uint64_t dfq_load_param(int snum, const char *path, const char *section,
const char *param, uint64_t def_val)
Expand Down Expand Up @@ -60,7 +60,7 @@ static bool dfq_disk_quotas(vfs_handle_struct *handle, const char *path,
id.uid = geteuid();

ZERO_STRUCT(D);
r = dfq_get_quota_do(handle, path, SMB_USER_QUOTA_TYPE, id, &D);
r = dfq_get_quota(handle, path, SMB_USER_QUOTA_TYPE, id, &D);

/* Use softlimit to determine disk space, except when it has been
* exceeded */
Expand Down Expand Up @@ -99,7 +99,7 @@ static bool dfq_disk_quotas(vfs_handle_struct *handle, const char *path,
id.gid = getegid();

ZERO_STRUCT(D);
r = dfq_get_quota_do(handle, path, SMB_GROUP_QUOTA_TYPE, id, &D);
r = dfq_get_quota(handle, path, SMB_GROUP_QUOTA_TYPE, id, &D);

/* Use softlimit to determine disk space, except when it has been
* exceeded */
Expand Down Expand Up @@ -181,9 +181,9 @@ static uint64_t dfq_disk_free(vfs_handle_struct *handle, const char *path,
return free_1k;
}

static int dfq_get_quota_do(struct vfs_handle_struct *handle, const char *path,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *qt)
static int dfq_get_quota(struct vfs_handle_struct *handle, const char *path,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *qt)
{
int rc = 0;
int save_errno;
Expand Down Expand Up @@ -245,7 +245,7 @@ static int dfq_get_quota_do(struct vfs_handle_struct *handle, const char *path,
goto out;

dflt:
rc = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
rc = SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, qt);

out:
save_errno = errno;
Expand All @@ -255,14 +255,6 @@ static int dfq_get_quota_do(struct vfs_handle_struct *handle, const char *path,
return rc;
}

static int dfq_get_quota(struct vfs_handle_struct *handle,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *qt)
{
return dfq_get_quota_do(handle, handle->conn->connectpath, qtype, id,
qt);
}

struct vfs_fn_pointers vfs_fake_dfq_fns = {
/* Disk operations */

Expand Down
8 changes: 4 additions & 4 deletions source3/modules/vfs_full_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,14 +666,14 @@ static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
}

static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *qt)
const char *path, enum SMB_QUOTA_TYPE qtype,
unid_t id, SMB_DISK_QUOTA *qt)
{
int result;

result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
result = SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, qt);

do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "%s", path);

return result;
}
Expand Down
6 changes: 3 additions & 3 deletions source3/modules/vfs_time_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ static uint64_t smb_time_audit_disk_free(vfs_handle_struct *handle,
}

static int smb_time_audit_get_quota(struct vfs_handle_struct *handle,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *qt)
const char *path, enum SMB_QUOTA_TYPE qtype,
unid_t id, SMB_DISK_QUOTA *qt)
{
int result;
struct timespec ts1,ts2;
double timediff;

clock_gettime_mono(&ts1);
result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
result = SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, qt);
clock_gettime_mono(&ts2);
timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;

Expand Down
2 changes: 1 addition & 1 deletion source3/smbd/ntquotas.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int vfs_get_ntquota(files_struct *fsp, enum SMB_QUOTA_TYPE qtype, struct dom_sid
sid_string_dbg(psid)));
}

ret = SMB_VFS_GET_QUOTA(fsp->conn, qtype, id, &D);
ret = SMB_VFS_GET_QUOTA(fsp->conn, ".", qtype, id, &D);

if (psid)
qt->sid = *psid;
Expand Down
4 changes: 2 additions & 2 deletions source3/smbd/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,12 +1404,12 @@ uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle,
return handle->fns->disk_free_fn(handle, path, bsize, dfree, dsize);
}

int smb_vfs_call_get_quota(struct vfs_handle_struct *handle,
int smb_vfs_call_get_quota(struct vfs_handle_struct *handle, const char *path,
enum SMB_QUOTA_TYPE qtype, unid_t id,
SMB_DISK_QUOTA *qt)
{
VFS_FIND(get_quota);
return handle->fns->get_quota_fn(handle, qtype, id, qt);
return handle->fns->get_quota_fn(handle, path, qtype, id, qt);
}

int smb_vfs_call_set_quota(struct vfs_handle_struct *handle,
Expand Down

0 comments on commit c464b9e

Please sign in to comment.