1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

vfs_ceph_snapshots: use OpenDir() in ceph_snap_enum_snapdir()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Ralph Boehme 2020-03-19 12:03:27 +01:00 committed by Jeremy Allison
parent afa69567cf
commit ec9fcb3113

View File

@ -176,10 +176,13 @@ static int ceph_snap_enum_snapdir(struct vfs_handle_struct *handle,
bool labels, bool labels,
struct shadow_copy_data *sc_data) struct shadow_copy_data *sc_data)
{ {
TALLOC_CTX *frame = talloc_stackframe();
struct smb_Dir *dir_hnd = NULL;
const char *dname = NULL;
char *talloced = NULL;
long offset = 0;
NTSTATUS status; NTSTATUS status;
int ret; int ret;
DIR *d = NULL;
struct dirent *e = NULL;
uint32_t slots; uint32_t slots;
status = smbd_check_access_rights(handle->conn, status = smbd_check_access_rights(handle->conn,
@ -203,8 +206,9 @@ static int ceph_snap_enum_snapdir(struct vfs_handle_struct *handle,
* place we need it (dir=.snap), so we need to dynamically determine it * place we need it (dir=.snap), so we need to dynamically determine it
* via readdir. * via readdir.
*/ */
d = SMB_VFS_NEXT_OPENDIR(handle, snaps_dname, NULL, 0);
if (d == NULL) { dir_hnd = OpenDir(frame, handle->conn, snaps_dname, NULL, 0);
if (dir_hnd == NULL) {
ret = -errno; ret = -errno;
goto err_out; goto err_out;
} }
@ -213,14 +217,16 @@ static int ceph_snap_enum_snapdir(struct vfs_handle_struct *handle,
sc_data->num_volumes = 0; sc_data->num_volumes = 0;
sc_data->labels = NULL; sc_data->labels = NULL;
for (e = SMB_VFS_NEXT_READDIR(handle, d, NULL); while ((dname = ReadDirName(dir_hnd, &offset, NULL, &talloced))
e != NULL; != NULL)
e = SMB_VFS_NEXT_READDIR(handle, d, NULL)) { {
if (ISDOT(e->d_name) || ISDOTDOT(e->d_name)) { if (ISDOT(dname) || ISDOTDOT(dname)) {
TALLOC_FREE(talloced);
continue; continue;
} }
sc_data->num_volumes++; sc_data->num_volumes++;
if (!labels) { if (!labels) {
TALLOC_FREE(talloced);
continue; continue;
} }
if (sc_data->num_volumes > slots) { if (sc_data->num_volumes > slots) {
@ -231,6 +237,7 @@ static int ceph_snap_enum_snapdir(struct vfs_handle_struct *handle,
SHADOW_COPY_LABEL, SHADOW_COPY_LABEL,
new_slot_count); new_slot_count);
if (sc_data->labels == NULL) { if (sc_data->labels == NULL) {
TALLOC_FREE(talloced);
ret = -ENOMEM; ret = -ENOMEM;
goto err_closedir; goto err_closedir;
} }
@ -242,28 +249,25 @@ static int ceph_snap_enum_snapdir(struct vfs_handle_struct *handle,
slots = new_slot_count; slots = new_slot_count;
} }
DBG_DEBUG("filling shadow copy label for %s/%s\n", DBG_DEBUG("filling shadow copy label for %s/%s\n",
snaps_dname->base_name, e->d_name); snaps_dname->base_name, dname);
ret = ceph_snap_fill_label(handle, snaps_dname, ret = ceph_snap_fill_label(handle, snaps_dname,
snaps_dname->base_name, e->d_name, snaps_dname->base_name, dname,
sc_data->labels[sc_data->num_volumes - 1]); sc_data->labels[sc_data->num_volumes - 1]);
if (ret < 0) { if (ret < 0) {
TALLOC_FREE(talloced);
goto err_closedir; goto err_closedir;
} }
} TALLOC_FREE(talloced);
ret = SMB_VFS_NEXT_CLOSEDIR(handle, d);
if (ret != 0) {
ret = -errno;
goto err_out;
} }
DBG_DEBUG("%s shadow copy enumeration found %d labels \n", DBG_DEBUG("%s shadow copy enumeration found %d labels \n",
snaps_dname->base_name, sc_data->num_volumes); snaps_dname->base_name, sc_data->num_volumes);
TALLOC_FREE(frame);
return 0; return 0;
err_closedir: err_closedir:
SMB_VFS_NEXT_CLOSEDIR(handle, d); TALLOC_FREE(frame);
err_out: err_out:
TALLOC_FREE(sc_data->labels); TALLOC_FREE(sc_data->labels);
return ret; return ret;