DEBUG offload copy/chunk
authorStefan Metzmacher <metze@samba.org>
Wed, 27 Mar 2019 11:41:40 +0000 (12:41 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 15 Oct 2019 07:36:38 +0000 (09:36 +0200)
selftest/gdb_backtrace
source3/modules/offload_token.c
source3/modules/vfs_default.c
source4/torture/smb2/ioctl.c

index ef02e784efc926277ab88664f588b3a2a587f97a..fe4ced397830505dcedf0a14c59ad5cdf142e947 100755 (executable)
@@ -2,14 +2,17 @@
 
 BASENAME=`basename $0`
 
+echo "METZE1 $0: $@"
+
 if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then
        echo "${BASENAME}: Not running debugger under valgrind"
        exit 1
 fi
 
 # we want everything on stderr, so the program is not disturbed
-exec 1>&2
+#exec 1>&2
 
+echo "METZE2 $0: $@"
 BASENAME=`basename $0`
 UNAME=`uname`
 
@@ -72,6 +75,8 @@ case "${DB}" in
        ;;
 esac
 
+echo "METZE... $0: $@"
+
 test x"${need_binary}" = x"yes" && {
 
 # we first try to use /proc/${PID}/exe or /proc/{$PID}/path for solaris
@@ -137,3 +142,4 @@ dbx)
        ;;
 esac
 /bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}
+echo "METZE3 $0: $@"
index 05528da46b5c4a5c8c5b908bcadffd79d4b5c9dd..fcea0c3ea7623679198266795f3dc863d8c0654d 100644 (file)
@@ -162,6 +162,7 @@ NTSTATUS vfs_offload_token_db_fetch_fsp(struct vfs_offload_ctx *ctx,
        TDB_DATA value;
        void *ptr = NULL;
 
+       DBG_ERR("%s: HERE\n", __location__);
        rec = dbwrap_fetch_locked(ctx->db_ctx, talloc_tos(), key);
        if (rec == NULL) {
                return NT_STATUS_INTERNAL_ERROR;
@@ -182,10 +183,13 @@ NTSTATUS vfs_offload_token_db_fetch_fsp(struct vfs_offload_ctx *ctx,
                return NT_STATUS_INTERNAL_ERROR;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        memcpy(&ptr, value.dptr, value.dsize);
        TALLOC_FREE(rec);
 
+       DBG_ERR("%s: HERE\n", __location__);
        *fsp = talloc_get_type_abort(ptr, struct files_struct);
+       DBG_ERR("%s: fsp[%p]\n", __location__, *fsp);
        return NT_STATUS_OK;
 }
 
@@ -226,50 +230,59 @@ NTSTATUS vfs_offload_token_check_handles(uint32_t fsctl,
                                         files_struct *src_fsp,
                                         files_struct *dst_fsp)
 {
+       DBG_ERR("%s: HERE\n", __location__);
        if (src_fsp->vuid != dst_fsp->vuid) {
                DBG_INFO("copy chunk handles not in the same session.\n");
                return NT_STATUS_ACCESS_DENIED;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        if (!NT_STATUS_IS_OK(src_fsp->op->status)) {
                DBG_INFO("copy chunk source handle invalid: %s\n",
                         nt_errstr(src_fsp->op->status));
                return NT_STATUS_ACCESS_DENIED;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        if (!NT_STATUS_IS_OK(dst_fsp->op->status)) {
                DBG_INFO("copy chunk destination handle invalid: %s\n",
                         nt_errstr(dst_fsp->op->status));
                return NT_STATUS_ACCESS_DENIED;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        if (src_fsp->deferred_close != NULL) {
                DBG_INFO("copy chunk src handle with deferred close.\n");
                return NT_STATUS_ACCESS_DENIED;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        if (dst_fsp->deferred_close != NULL) {
                DBG_INFO("copy chunk dst handle with deferred close.\n");
                return NT_STATUS_ACCESS_DENIED;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        if (src_fsp->is_directory) {
                DBG_INFO("copy chunk no read on src directory handle (%s).\n",
                         smb_fname_str_dbg(src_fsp->fsp_name));
                return NT_STATUS_ACCESS_DENIED;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        if (dst_fsp->is_directory) {
                DBG_INFO("copy chunk no read on dst directory handle (%s).\n",
                         smb_fname_str_dbg(dst_fsp->fsp_name));
                return NT_STATUS_ACCESS_DENIED;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        if (IS_IPC(src_fsp->conn) || IS_IPC(dst_fsp->conn)) {
                DBG_INFO("copy chunk no access on IPC$ handle.\n");
                return NT_STATUS_ACCESS_DENIED;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        if (IS_PRINT(src_fsp->conn) || IS_PRINT(dst_fsp->conn)) {
                DBG_INFO("copy chunk no access on PRINT handle.\n");
                return NT_STATUS_ACCESS_DENIED;
@@ -284,11 +297,13 @@ NTSTATUS vfs_offload_token_check_handles(uint32_t fsctl,
         *
         * A non writable dst handle also doesn't make sense for other fsctls.
         */
+       DBG_ERR("%s: HERE\n", __location__);
        if (!CHECK_WRITE(dst_fsp)) {
                DBG_INFO("dest handle not writable (%s).\n",
                        smb_fname_str_dbg(dst_fsp->fsp_name));
                return NT_STATUS_ACCESS_DENIED;
        }
+       DBG_ERR("%s: HERE\n", __location__);
        /*
         * - The Open.GrantedAccess of the destination file does not include
         *   FILE_READ_DATA, and the CtlCode is FSCTL_SRV_COPYCHUNK.
@@ -298,6 +313,7 @@ NTSTATUS vfs_offload_token_check_handles(uint32_t fsctl,
                         smb_fname_str_dbg(dst_fsp->fsp_name));
                return NT_STATUS_ACCESS_DENIED;
        }
+       DBG_ERR("%s: HERE\n", __location__);
        /*
         * - The Open.GrantedAccess of the source file does not include
         *   FILE_READ_DATA access.
@@ -308,5 +324,6 @@ NTSTATUS vfs_offload_token_check_handles(uint32_t fsctl,
                return NT_STATUS_ACCESS_DENIED;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        return NT_STATUS_OK;
 }
index 13d849c5084d7dd68b052def9ce887f07f36ec40..fbe1b9cdf38b25a698ec53ebb4f587546119fdfd 100644 (file)
@@ -801,6 +801,7 @@ static struct tevent_req *vfswrap_pwrite_send(struct vfs_handle_struct *handle,
        state->count = n;
        state->offset = offset;
 
+       DBG_ERR("%s: HERE\n", __location__);
        SMBPROFILE_BYTES_ASYNC_START(syscall_asys_pwrite, profile_p,
                                     state->profile_bytes, n);
        SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
@@ -1822,6 +1823,12 @@ static struct tevent_req *vfswrap_offload_write_send(
                .remaining = to_copy,
        };
 
+       DBG_ERR("src_off[%lld] dst_off[%lld] to_copy[%u] num[%zu]\n",
+               (long long)state->src_off,
+               (long long)state->dst_off,
+               (unsigned)state->to_copy,
+               num);
+
        tevent_req_set_cleanup_fn(req, vfswrap_offload_write_cleanup);
 
        switch (fsctl) {
@@ -1852,43 +1859,59 @@ static struct tevent_req *vfswrap_offload_write_send(
                return tevent_req_post(req, ev);
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
+if (1) {
        if (state->src_off > max_offset) {
                /*
                 * Protect integer checks below.
                 */
                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+       DBG_ERR("%s: HERE\n", __location__);
+               //smb_panic(__location__);
                return tevent_req_post(req, ev);
        }
+       DBG_ERR("%s: HERE\n", __location__);
        if (state->src_off < 0) {
                /*
                 * Protect integer checks below.
                 */
                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+       DBG_ERR("%s: HERE\n", __location__);
+       //      smb_panic(__location__);
                return tevent_req_post(req, ev);
        }
+       DBG_ERR("%s: HERE\n", __location__);
        if (state->dst_off > max_offset) {
                /*
                 * Protect integer checks below.
                 */
                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+       DBG_ERR("%s: HERE\n", __location__);
+       //      smb_panic(__location__);
                return tevent_req_post(req, ev);
        }
+       DBG_ERR("%s: HERE\n", __location__);
        if (state->dst_off < 0) {
                /*
                 * Protect integer checks below.
                 */
                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+       DBG_ERR("%s: HERE\n", __location__);
+       //      smb_panic(__location__);
                return tevent_req_post(req, ev);
        }
+}
 
+       DBG_ERR("%s: HERE\n", __location__);
        status = vfs_offload_token_db_fetch_fsp(vfswrap_offload_ctx,
                                                token, &src_fsp);
+       DBG_ERR("%s: src_fsp[%p] %s\n", __location__, src_fsp, nt_errstr(status));
        if (tevent_req_nterror(req, status)) {
                return tevent_req_post(req, ev);
        }
-
        DBG_DEBUG("server side copy chunk of length %" PRIu64 "\n", to_copy);
 
+       DBG_ERR("%s: HERE\n", __location__);
        status = vfs_offload_token_check_handles(fsctl, src_fsp, dest_fsp);
        if (!NT_STATUS_IS_OK(status)) {
                tevent_req_nterror(req, status);
@@ -1909,6 +1932,7 @@ static struct tevent_req *vfswrap_offload_write_send(
                return tevent_req_post(req, ev);
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        if (src_fsp->fsp_name->st.st_ex_size < state->src_off + to_copy) {
                /*
                 * [MS-SMB2] 3.3.5.15.6 Handling a Server-Side Data Copy Request
@@ -1919,10 +1943,12 @@ static struct tevent_req *vfswrap_offload_write_send(
                 *   <240> Section 3.3.5.15.6: Windows servers will return
                 *   STATUS_INVALID_VIEW_SIZE instead of STATUS_END_OF_FILE.
                 */
+       DBG_ERR("%s: HERE\n", __location__);
                tevent_req_nterror(req, NT_STATUS_INVALID_VIEW_SIZE);
                return tevent_req_post(req, ev);
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        state->buf = talloc_array(state, uint8_t, num);
        if (tevent_req_nomem(state->buf, req)) {
                return tevent_req_post(req, ev);
@@ -1951,6 +1977,7 @@ static NTSTATUS vfswrap_offload_write_loop(struct tevent_req *req)
         * This is called under the context of state->src_fsp.
         */
 
+       DBG_ERR("%s: HERE\n", __location__);
        state->next_io_size = MIN(state->remaining, talloc_array_length(state->buf));
 
        init_strict_lock_struct(state->src_fsp,
@@ -1967,6 +1994,7 @@ static NTSTATUS vfswrap_offload_write_loop(struct tevent_req *req)
                return NT_STATUS_FILE_LOCK_CONFLICT;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        subreq = SMB_VFS_PREAD_SEND(state,
                                    state->src_ev,
                                    state->src_fsp,
@@ -2031,6 +2059,7 @@ static void vfswrap_offload_write_read_done(struct tevent_req *subreq)
                return;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        subreq = SMB_VFS_PWRITE_SEND(state,
                                     state->dst_ev,
                                     state->dst_fsp,
@@ -2105,14 +2134,16 @@ static NTSTATUS vfswrap_offload_write_recv(struct vfs_handle_struct *handle,
        NTSTATUS status;
 
        if (tevent_req_is_nterror(req, &status)) {
-               DBG_DEBUG("copy chunk failed: %s\n", nt_errstr(status));
+       DBG_ERR("%s: HERE\n", __location__);
+               DBG_ERR("copy chunk failed: %s\n", nt_errstr(status));
                *copied = 0;
                tevent_req_received(req);
                return status;
        }
 
+       DBG_ERR("%s: HERE\n", __location__);
        *copied = state->to_copy;
-       DBG_DEBUG("copy chunk copied %lu\n", (unsigned long)*copied);
+       DBG_ERR("copy chunk copied %lu\n", (unsigned long)*copied);
        tevent_req_received(req);
 
        return NT_STATUS_OK;
index 60b261186265c70314e04f7e4d6a41f17327b1f5..884159a4714f2b74bea61488265ba425e0a84235 100644 (file)
@@ -822,32 +822,32 @@ static bool test_ioctl_copy_chunk_limits(struct torture_context *torture,
                torture_fail(torture, "setup copy chunk error");
        }
 
-       /* send huge chunk length request */
-       cc_copy.chunks[0].source_off = 0;
-       cc_copy.chunks[0].target_off = 0;
-       cc_copy.chunks[0].length = UINT_MAX;
-
-       ndr_ret = ndr_push_struct_blob(&ioctl.smb2.in.out, tmp_ctx,
-                                      &cc_copy,
-                       (ndr_push_flags_fn_t)ndr_push_srv_copychunk_copy);
-       torture_assert_ndr_success(torture, ndr_ret, "marshalling request");
-
-       status = smb2_ioctl(tree, tmp_ctx, &ioctl.smb2);
-       torture_assert_ntstatus_equal(torture, status,
-                                     NT_STATUS_INVALID_PARAMETER,
-                                     "bad oversize chunk response");
-
-       ndr_ret = ndr_pull_struct_blob(&ioctl.smb2.out.out, tmp_ctx,
-                                      &cc_rsp,
-                       (ndr_pull_flags_fn_t)ndr_pull_srv_copychunk_rsp);
-       torture_assert_ndr_success(torture, ndr_ret, "unmarshalling response");
-
-       torture_comment(torture, "limit max chunks, got %u\n",
-                       cc_rsp.chunks_written);
-       torture_comment(torture, "limit max chunk len, got %u\n",
-                       cc_rsp.chunk_bytes_written);
-       torture_comment(torture, "limit max total bytes, got %u\n",
-                       cc_rsp.total_bytes_written);
+//     /* send huge chunk length request */
+//     cc_copy.chunks[0].source_off = 0;
+//     cc_copy.chunks[0].target_off = 0;
+//     cc_copy.chunks[0].length = UINT_MAX;
+//
+//     ndr_ret = ndr_push_struct_blob(&ioctl.smb2.in.out, tmp_ctx,
+//                                    &cc_copy,
+//                     (ndr_push_flags_fn_t)ndr_push_srv_copychunk_copy);
+//     torture_assert_ndr_success(torture, ndr_ret, "marshalling request");
+//
+//     status = smb2_ioctl(tree, tmp_ctx, &ioctl.smb2);
+//     torture_assert_ntstatus_equal(torture, status,
+//                                   NT_STATUS_INVALID_PARAMETER,
+//                                   "bad oversize chunk response");
+
+//     ndr_ret = ndr_pull_struct_blob(&ioctl.smb2.out.out, tmp_ctx,
+//                                    &cc_rsp,
+//                     (ndr_pull_flags_fn_t)ndr_pull_srv_copychunk_rsp);
+//     torture_assert_ndr_success(torture, ndr_ret, "unmarshalling response");
+//
+//     torture_comment(torture, "limit max chunks, got %u\n",
+//                     cc_rsp.chunks_written);
+//     torture_comment(torture, "limit max chunk len, got %u\n",
+//                     cc_rsp.chunk_bytes_written);
+//     torture_comment(torture, "limit max total bytes, got %u\n",
+//                     cc_rsp.total_bytes_written);
 
        /* send huge chunk length request */
        cc_copy.chunks[0].source_off = UINT64_MAX;
@@ -6826,7 +6826,7 @@ static bool test_ioctl_dup_extents_dest_lck(struct torture_context *tctx,
 struct torture_suite *torture_smb2_ioctl_init(TALLOC_CTX *ctx)
 {
        struct torture_suite *suite = torture_suite_create(ctx, "ioctl");
-
+if (0) {
        torture_suite_add_1smb2_test(suite, "shadow_copy",
                                     test_ioctl_get_shadow_copy);
        torture_suite_add_1smb2_test(suite, "req_resume_key",
@@ -6843,8 +6843,10 @@ struct torture_suite *torture_smb2_ioctl_init(TALLOC_CTX *ctx)
                                     test_ioctl_copy_chunk_over);
        torture_suite_add_1smb2_test(suite, "copy_chunk_append",
                                     test_ioctl_copy_chunk_append);
+}
        torture_suite_add_1smb2_test(suite, "copy_chunk_limits",
                                     test_ioctl_copy_chunk_limits);
+if (0) {
        torture_suite_add_1smb2_test(suite, "copy_chunk_src_lock",
                                     test_ioctl_copy_chunk_src_lck);
        torture_suite_add_1smb2_test(suite, "copy_chunk_dest_lock",
@@ -6965,7 +6967,7 @@ struct torture_suite *torture_smb2_ioctl_init(TALLOC_CTX *ctx)
                                     test_ioctl_dup_extents_src_lck);
        torture_suite_add_1smb2_test(suite, "dup_extents_dest_lock",
                                     test_ioctl_dup_extents_dest_lck);
-
+}
        suite->description = talloc_strdup(suite, "SMB2-IOCTL tests");
 
        return suite;