-static void copychunk_unlock_all(struct files_struct *src_fsp,
- struct files_struct *dst_fsp,
- struct lock_struct *rd_locks,
- struct lock_struct *wr_locks,
- uint32_t num_locks)
-{
-
- uint32_t i;
-
- for (i = 0; i < num_locks; i++) {
- SMB_VFS_STRICT_UNLOCK(src_fsp->conn, src_fsp, &rd_locks[i]);
- SMB_VFS_STRICT_UNLOCK(dst_fsp->conn, dst_fsp, &wr_locks[i]);
- }
-}
-
-/* request read and write locks for each chunk */
-static NTSTATUS copychunk_lock_all(TALLOC_CTX *mem_ctx,
- struct srv_copychunk_copy *cc_copy,
- struct files_struct *src_fsp,
- struct files_struct *dst_fsp,
- struct lock_struct **rd_locks,
- struct lock_struct **wr_locks,
- uint32_t *num_locks)
-{
- NTSTATUS status;
- uint32_t i;
- struct lock_struct *rlocks;
- struct lock_struct *wlocks;
-
- rlocks = talloc_array(mem_ctx, struct lock_struct,
- cc_copy->chunk_count);
- if (rlocks == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto err_out;
- }
-
- wlocks = talloc_array(mem_ctx, struct lock_struct,
- cc_copy->chunk_count);
- if (wlocks == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto err_rlocks_free;
- }
-
- for (i = 0; i < cc_copy->chunk_count; i++) {
- init_strict_lock_struct(src_fsp,
- src_fsp->op->global->open_persistent_id,
- cc_copy->chunks[i].source_off,
- cc_copy->chunks[i].length,
- READ_LOCK,
- &rlocks[i]);
- init_strict_lock_struct(dst_fsp,
- dst_fsp->op->global->open_persistent_id,
- cc_copy->chunks[i].target_off,
- cc_copy->chunks[i].length,
- WRITE_LOCK,
- &wlocks[i]);
-
- if (!SMB_VFS_STRICT_LOCK(src_fsp->conn, src_fsp, &rlocks[i])) {
- status = NT_STATUS_FILE_LOCK_CONFLICT;
- goto err_unlock;
- }
- if (!SMB_VFS_STRICT_LOCK(dst_fsp->conn, dst_fsp, &wlocks[i])) {
- /* unlock last rlock, otherwise missed by cleanup */
- SMB_VFS_STRICT_UNLOCK(src_fsp->conn, src_fsp,
- &rlocks[i]);
- status = NT_STATUS_FILE_LOCK_CONFLICT;
- goto err_unlock;
- }
- }
-
- *rd_locks = rlocks;
- *wr_locks = wlocks;
- *num_locks = i;
-
- return NT_STATUS_OK;
-
-err_unlock:
- if (i > 0) {
- /* cleanup all locks successfully issued so far */
- copychunk_unlock_all(src_fsp, dst_fsp, rlocks, wlocks, i);
- }
- talloc_free(wlocks);
-err_rlocks_free:
- talloc_free(rlocks);
-err_out:
- return status;
-}
-