1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

vfs: SMB_VFS_GET_COMPRESSION() -> SMB_VFS_FGET_COMPRESSION()

Now that handle based fdos_mode() is used everywhere we can be sure that we're
also always getting a handle in SMB_VFS_GET_COMPRESSION() so we can now safely
remove the path parameter. :)

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Ralph Boehme 2020-10-13 12:02:34 +02:00
parent 3db25c1c9b
commit a55a2bfb91
14 changed files with 82 additions and 131 deletions

View File

@ -60,6 +60,7 @@
<member>fchmod</member>
<member>fchown</member>
<member>fdopendir</member>
<member>fget_compression</member>
<member>fget_dos_attributes</member>
<member>fget_nt_acl_at</member>
<member>fgetxattr</member>
@ -78,7 +79,6 @@
<member>fsync_send</member>
<member>ftruncate</member>
<member>get_alloc_size</member>
<member>get_compression</member>
<member>get_dfs_referrals</member>
<member>get_dos_attributes</member>
<member>get_dos_attributes_recv</member>

View File

@ -620,10 +620,9 @@ static NTSTATUS skel_offload_write_recv(struct vfs_handle_struct *handle,
return NT_STATUS_OK;
}
static NTSTATUS skel_get_compression(struct vfs_handle_struct *handle,
static NTSTATUS skel_fget_compression(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt)
{
return NT_STATUS_INVALID_DEVICE_REQUEST;
@ -1106,7 +1105,7 @@ static struct vfs_fn_pointers skel_opaque_fns = {
.offload_read_recv_fn = skel_offload_read_recv,
.offload_write_send_fn = skel_offload_write_send,
.offload_write_recv_fn = skel_offload_write_recv,
.get_compression_fn = skel_get_compression,
.fget_compression_fn = skel_fget_compression,
.set_compression_fn = skel_set_compression,
.streaminfo_fn = skel_streaminfo,

View File

@ -829,13 +829,12 @@ static NTSTATUS skel_offload_write_recv(struct vfs_handle_struct *handle,
return NT_STATUS_OK;
}
static NTSTATUS skel_get_compression(struct vfs_handle_struct *handle,
static NTSTATUS skel_fget_compression(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt)
{
return SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
return SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
_compression_fmt);
}
@ -1411,7 +1410,7 @@ static struct vfs_fn_pointers skel_transparent_fns = {
.offload_read_recv_fn = skel_offload_read_recv,
.offload_write_send_fn = skel_offload_write_send,
.offload_write_recv_fn = skel_offload_write_recv,
.get_compression_fn = skel_get_compression,
.fget_compression_fn = skel_fget_compression,
.set_compression_fn = skel_set_compression,
.streaminfo_fn = skel_streaminfo,

View File

@ -339,6 +339,7 @@
* Version 44 - Add 'have_proc_fds' flag to struct files_struct.
* Version 44 - Add dirfsp arg to SMB_VFS_READDIR()
* Version 44 - Remove SMB_VFS_GET_DOS_ATTRIBUTES()
* Version 44 - Replace SMB_VFS_GET_COMPRESSION() with SMB_VFS_FGET_COMPRESSION()
*/
#define SMB_VFS_INTERFACE_VERSION 44
@ -1080,10 +1081,9 @@ struct vfs_fn_pointers {
NTSTATUS (*offload_write_recv_fn)(struct vfs_handle_struct *handle,
struct tevent_req *req,
off_t *copied);
NTSTATUS (*get_compression_fn)(struct vfs_handle_struct *handle,
NTSTATUS (*fget_compression_fn)(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt);
NTSTATUS (*set_compression_fn)(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
@ -1678,10 +1678,9 @@ struct tevent_req *smb_vfs_call_offload_write_send(struct vfs_handle_struct *han
NTSTATUS smb_vfs_call_offload_write_recv(struct vfs_handle_struct *handle,
struct tevent_req *req,
off_t *copied);
NTSTATUS smb_vfs_call_get_compression(struct vfs_handle_struct *handle,
NTSTATUS smb_vfs_call_fget_compression(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt);
NTSTATUS smb_vfs_call_set_compression(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
@ -2068,10 +2067,9 @@ struct tevent_req *vfs_not_implemented_offload_write_send(
NTSTATUS vfs_not_implemented_offload_write_recv(struct vfs_handle_struct *handle,
struct tevent_req *req,
off_t *copied);
NTSTATUS vfs_not_implemented_get_compression(struct vfs_handle_struct *handle,
NTSTATUS vfs_not_implemented_fget_compression(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt);
NTSTATUS vfs_not_implemented_set_compression(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,

View File

@ -443,10 +443,10 @@
#define SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied) \
smb_vfs_call_offload_write_recv((handle)->next, (req), (copied))
#define SMB_VFS_GET_COMPRESSION(conn, mem_ctx, fsp, smb_fname, _compression_fmt) \
smb_vfs_call_get_compression((conn)->vfs_handles, (mem_ctx), (fsp), (smb_fname), (_compression_fmt))
#define SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname, _compression_fmt) \
smb_vfs_call_get_compression((handle)->next, (mem_ctx), (fsp), (smb_fname), (_compression_fmt))
#define SMB_VFS_FGET_COMPRESSION(conn, mem_ctx, fsp, _compression_fmt) \
smb_vfs_call_fget_compression((conn)->vfs_handles, (mem_ctx), (fsp), (_compression_fmt))
#define SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp, _compression_fmt) \
smb_vfs_call_fget_compression((handle)->next, (mem_ctx), (fsp), (_compression_fmt))
#define SMB_VFS_SET_COMPRESSION(conn, mem_ctx, fsp, compression_fmt) \
smb_vfs_call_set_compression((conn)->vfs_handles, (mem_ctx), (fsp), (compression_fmt))

View File

@ -451,46 +451,48 @@ static NTSTATUS btrfs_offload_write_recv(struct vfs_handle_struct *handle,
return NT_STATUS_OK;
}
/*
* caller must pass a non-null fsp or smb_fname. If fsp is null, then
* fall back to opening the corresponding file to issue the ioctl.
*/
static NTSTATUS btrfs_get_compression(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt)
static NTSTATUS btrfs_fget_compression(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
uint16_t *_compression_fmt)
{
char buf[PATH_MAX];
const char *p = NULL;
int ret;
long flags = 0;
int fd;
bool opened = false;
int fd = -1;
NTSTATUS status;
DIR *dir = NULL;
if ((fsp != NULL) && (fsp_get_io_fd(fsp) != -1)) {
fd = fsp_get_io_fd(fsp);
} else if (smb_fname != NULL) {
if (S_ISDIR(smb_fname->st.st_ex_mode)) {
dir = opendir(smb_fname->base_name);
if (dir == NULL) {
return NT_STATUS_UNSUCCESSFUL;
}
opened = true;
fd = dirfd(dir);
if (fd < 0) {
status = NT_STATUS_UNSUCCESSFUL;
goto err_close;
}
} else {
fd = open(smb_fname->base_name, O_RDONLY);
if (fd < 0) {
return NT_STATUS_UNSUCCESSFUL;
}
opened = true;
if (!fsp->fsp_flags.is_pathref) {
ret = ioctl(fd, FS_IOC_GETFLAGS, &flags);
if (ret < 0) {
DBG_WARNING("FS_IOC_GETFLAGS failed: %s, fd %lld\n",
strerror(errno), (long long)fd);
return map_nt_error_from_unix(errno);
}
} else {
return NT_STATUS_INVALID_PARAMETER;
if (flags & FS_COMPR_FL) {
*_compression_fmt = COMPRESSION_FORMAT_LZNT1;
} else {
*_compression_fmt = COMPRESSION_FORMAT_NONE;
}
return NT_STATUS_OK;
}
if (!fsp->fsp_flags.have_proc_fds) {
return NT_STATUS_NOT_IMPLEMENTED;
}
fd = fsp_get_pathref_fd(fsp);
p = sys_proc_fd_path(fd, buf, sizeof(buf));
if (p == NULL) {
return NT_STATUS_NO_MEMORY;
}
fd = open(p, O_RDONLY);
if (fd == -1) {
DBG_ERR("/proc open of %s failed: %s\n", p, strerror(errno));
return map_nt_error_from_unix(errno);
}
ret = ioctl(fd, FS_IOC_GETFLAGS, &flags);
@ -506,13 +508,10 @@ static NTSTATUS btrfs_get_compression(struct vfs_handle_struct *handle,
*_compression_fmt = COMPRESSION_FORMAT_NONE;
}
status = NT_STATUS_OK;
err_close:
if (opened) {
if (dir != NULL) {
closedir(dir);
} else {
close(fd);
}
if (fd != -1) {
close(fd);
}
return status;
@ -868,7 +867,7 @@ static struct vfs_fn_pointers btrfs_fns = {
.offload_read_recv_fn = btrfs_offload_read_recv,
.offload_write_send_fn = btrfs_offload_write_send,
.offload_write_recv_fn = btrfs_offload_write_recv,
.get_compression_fn = btrfs_get_compression,
.fget_compression_fn = btrfs_fget_compression,
.set_compression_fn = btrfs_set_compression,
.snap_check_path_fn = btrfs_snap_check_path,
.snap_create_fn = btrfs_snap_create,

View File

@ -2190,58 +2190,26 @@ static NTSTATUS catia_fsctl(struct vfs_handle_struct *handle,
return result;
}
static NTSTATUS catia_get_compression(vfs_handle_struct *handle,
static NTSTATUS catia_fget_compression(vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt)
{
NTSTATUS result;
struct catia_cache *cc = NULL;
int ret;
struct smb_filename *mapped_smb_fname = NULL;
char *mapped_name = NULL;
if (fsp != NULL) {
ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
if (ret != 0) {
return map_nt_error_from_unix(errno);
}
mapped_smb_fname = fsp->fsp_name;
} else {
result = catia_string_replace_allocate(handle->conn,
smb_fname->base_name,
&mapped_name,
vfs_translate_to_unix);
if (!NT_STATUS_IS_OK(result)) {
return result;
}
mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
mapped_name,
NULL,
&smb_fname->st,
smb_fname->twrp,
smb_fname->flags);
if (mapped_smb_fname == NULL) {
TALLOC_FREE(mapped_name);
return NT_STATUS_NO_MEMORY;
}
TALLOC_FREE(mapped_name);
ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
if (ret != 0) {
return map_nt_error_from_unix(errno);
}
result = SMB_VFS_NEXT_GET_COMPRESSION(handle,
result = SMB_VFS_NEXT_FGET_COMPRESSION(handle,
mem_ctx,
fsp,
mapped_smb_fname,
_compression_fmt);
if (fsp != NULL) {
CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
} else {
TALLOC_FREE(mapped_smb_fname);
}
CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
return result;
}
@ -2468,7 +2436,7 @@ static struct vfs_fn_pointers vfs_catia_fns = {
.set_dos_attributes_fn = catia_set_dos_attributes,
.fset_dos_attributes_fn = catia_fset_dos_attributes,
.fget_dos_attributes_fn = catia_fget_dos_attributes,
.get_compression_fn = catia_get_compression,
.fget_compression_fn = catia_fget_compression,
.set_compression_fn = catia_set_compression,
.create_dfs_pathat_fn = catia_create_dfs_pathat,
.read_dfs_pathat_fn = catia_read_dfs_pathat,

View File

@ -2337,10 +2337,9 @@ static NTSTATUS vfswrap_offload_write_recv(struct vfs_handle_struct *handle,
return NT_STATUS_OK;
}
static NTSTATUS vfswrap_get_compression(struct vfs_handle_struct *handle,
static NTSTATUS vfswrap_fget_compression(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt)
{
return NT_STATUS_INVALID_DEVICE_REQUEST;
@ -3863,7 +3862,7 @@ static struct vfs_fn_pointers vfs_default_fns = {
.offload_read_recv_fn = vfswrap_offload_read_recv,
.offload_write_send_fn = vfswrap_offload_write_send,
.offload_write_recv_fn = vfswrap_offload_write_recv,
.get_compression_fn = vfswrap_get_compression,
.fget_compression_fn = vfswrap_fget_compression,
.set_compression_fn = vfswrap_set_compression,
/* NT ACL operations. */

View File

@ -175,7 +175,7 @@ typedef enum _vfs_op_type {
SMB_VFS_OP_OFFLOAD_READ_RECV,
SMB_VFS_OP_OFFLOAD_WRITE_SEND,
SMB_VFS_OP_OFFLOAD_WRITE_RECV,
SMB_VFS_OP_GET_COMPRESSION,
SMB_VFS_OP_FGET_COMPRESSION,
SMB_VFS_OP_SET_COMPRESSION,
SMB_VFS_OP_SNAP_CHECK_PATH,
SMB_VFS_OP_SNAP_CREATE,
@ -318,7 +318,7 @@ static struct {
{ SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
{ SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
{ SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
{ SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
{ SMB_VFS_OP_FGET_COMPRESSION, "fget_compression" },
{ SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
{ SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
{ SMB_VFS_OP_SNAP_CREATE, "snap_create" },
@ -2172,21 +2172,19 @@ static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *hand
return result;
}
static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
static NTSTATUS smb_full_audit_fget_compression(vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt)
{
NTSTATUS result;
result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
_compression_fmt);
do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
do_log(SMB_VFS_OP_FGET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
"%s",
(fsp ? fsp_str_do_log(fsp) :
smb_fname_str_do_log(handle->conn, smb_fname)));
fsp_str_do_log(fsp));
return result;
}
@ -3016,7 +3014,7 @@ static struct vfs_fn_pointers vfs_full_audit_fns = {
.offload_read_recv_fn = smb_full_audit_offload_read_recv,
.offload_write_send_fn = smb_full_audit_offload_write_send,
.offload_write_recv_fn = smb_full_audit_offload_write_recv,
.get_compression_fn = smb_full_audit_get_compression,
.fget_compression_fn = smb_full_audit_fget_compression,
.set_compression_fn = smb_full_audit_set_compression,
.snap_check_path_fn = smb_full_audit_snap_check_path,
.snap_create_fn = smb_full_audit_snap_create,

View File

@ -622,10 +622,9 @@ NTSTATUS vfs_not_implemented_offload_write_recv(struct vfs_handle_struct *handle
return NT_STATUS_OK;
}
NTSTATUS vfs_not_implemented_get_compression(struct vfs_handle_struct *handle,
NTSTATUS vfs_not_implemented_fget_compression(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt)
{
return NT_STATUS_INVALID_DEVICE_REQUEST;
@ -1110,7 +1109,7 @@ static struct vfs_fn_pointers vfs_not_implemented_fns = {
.offload_read_recv_fn = vfs_not_implemented_offload_read_recv,
.offload_write_send_fn = vfs_not_implemented_offload_write_send,
.offload_write_recv_fn = vfs_not_implemented_offload_write_recv,
.get_compression_fn = vfs_not_implemented_get_compression,
.fget_compression_fn = vfs_not_implemented_fget_compression,
.set_compression_fn = vfs_not_implemented_set_compression,
.streaminfo_fn = vfs_not_implemented_streaminfo,

View File

@ -2126,10 +2126,9 @@ static NTSTATUS smb_time_audit_offload_write_recv(struct vfs_handle_struct *hand
return NT_STATUS_OK;
}
static NTSTATUS smb_time_audit_get_compression(vfs_handle_struct *handle,
static NTSTATUS smb_time_audit_fget_compression(vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt)
{
NTSTATUS result;
@ -2137,19 +2136,14 @@ static NTSTATUS smb_time_audit_get_compression(vfs_handle_struct *handle,
double timediff;
clock_gettime_mono(&ts1);
result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
_compression_fmt);
clock_gettime_mono(&ts2);
timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
if (timediff > audit_timeout) {
if (fsp != NULL) {
smb_time_audit_log_fsp("get_compression",
timediff, fsp);
} else {
smb_time_audit_log_smb_fname("get_compression",
timediff, smb_fname);
}
smb_time_audit_log_fsp("get_compression",
timediff, fsp);
}
return result;
@ -2884,7 +2878,7 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
.offload_read_recv_fn = smb_time_audit_offload_read_recv,
.offload_write_send_fn = smb_time_audit_offload_write_send,
.offload_write_recv_fn = smb_time_audit_offload_write_recv,
.get_compression_fn = smb_time_audit_get_compression,
.fget_compression_fn = smb_time_audit_fget_compression,
.set_compression_fn = smb_time_audit_set_compression,
.snap_check_path_fn = smb_time_audit_snap_check_path,
.snap_create_fn = smb_time_audit_snap_create,

View File

@ -609,7 +609,7 @@ static NTSTATUS dos_mode_check_compressed(connection_struct *conn,
goto err_out;
}
status = SMB_VFS_GET_COMPRESSION(conn, tmp_ctx, fsp, smb_fname,
status = SMB_VFS_FGET_COMPRESSION(conn, tmp_ctx, fsp,
&compression_fmt);
if (!NT_STATUS_IS_OK(status)) {
goto err_ctx_free;

View File

@ -353,10 +353,9 @@ static NTSTATUS fsctl_get_cmprn(TALLOC_CTX *mem_ctx,
ZERO_STRUCT(cmpr_state);
if (fsp->conn->fs_capabilities & FILE_FILE_COMPRESSION) {
status = SMB_VFS_GET_COMPRESSION(fsp->conn,
status = SMB_VFS_FGET_COMPRESSION(fsp->conn,
mem_ctx,
fsp,
NULL,
&cmpr_state.format);
if (!NT_STATUS_IS_OK(status)) {
return status;

View File

@ -2623,14 +2623,13 @@ NTSTATUS smb_vfs_call_get_dos_attributes_recv(
return NT_STATUS_OK;
}
NTSTATUS smb_vfs_call_get_compression(vfs_handle_struct *handle,
NTSTATUS smb_vfs_call_fget_compression(vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct files_struct *fsp,
struct smb_filename *smb_fname,
uint16_t *_compression_fmt)
{
VFS_FIND(get_compression);
return handle->fns->get_compression_fn(handle, mem_ctx, fsp, smb_fname,
VFS_FIND(fget_compression);
return handle->fns->fget_compression_fn(handle, mem_ctx, fsp,
_compression_fmt);
}