Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag '4.20-rc1-smb3-fixes' of git://git.samba.org/sfrench/cifs-2.6

Pull cifs fixes and updates from Steve French:
"Three small fixes (one Kerberos related, one for stable, and another
fixes an oops in xfstest 377), two helpful debugging improvements,
three patches for cifs directio and some minor cleanup"

* tag '4.20-rc1-smb3-fixes' of git://git.samba.org/sfrench/cifs-2.6:
cifs: fix signed/unsigned mismatch on aio_read patch
cifs: don't dereference smb_file_target before null check
CIFS: Add direct I/O functions to file_operations
CIFS: Add support for direct I/O write
CIFS: Add support for direct I/O read
smb3: missing defines and structs for reparse point handling
smb3: allow more detailed protocol info on open files for debugging
smb3: on kerberos mount if server doesn't specify auth type use krb5
smb3: add trace point for tree connection
cifs: fix spelling mistake, EACCESS -> EACCES
cifs: fix return value for cifs_listxattr

+530 -99
+56
fs/cifs/cifs_debug.c
··· 145 145 seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr); 146 146 } 147 147 148 + static int cifs_debug_files_proc_show(struct seq_file *m, void *v) 149 + { 150 + struct list_head *stmp, *tmp, *tmp1, *tmp2; 151 + struct TCP_Server_Info *server; 152 + struct cifs_ses *ses; 153 + struct cifs_tcon *tcon; 154 + struct cifsFileInfo *cfile; 155 + 156 + seq_puts(m, "# Version:1\n"); 157 + seq_puts(m, "# Format:\n"); 158 + seq_puts(m, "# <tree id> <persistent fid> <flags> <count> <pid> <uid>"); 159 + #ifdef CONFIG_CIFS_DEBUG2 160 + seq_printf(m, " <filename> <mid>\n"); 161 + #else 162 + seq_printf(m, " <filename>\n"); 163 + #endif /* CIFS_DEBUG2 */ 164 + spin_lock(&cifs_tcp_ses_lock); 165 + list_for_each(stmp, &cifs_tcp_ses_list) { 166 + server = list_entry(stmp, struct TCP_Server_Info, 167 + tcp_ses_list); 168 + list_for_each(tmp, &server->smb_ses_list) { 169 + ses = list_entry(tmp, struct cifs_ses, smb_ses_list); 170 + list_for_each(tmp1, &ses->tcon_list) { 171 + tcon = list_entry(tmp1, struct cifs_tcon, tcon_list); 172 + spin_lock(&tcon->open_file_lock); 173 + list_for_each(tmp2, &tcon->openFileList) { 174 + cfile = list_entry(tmp2, struct cifsFileInfo, 175 + tlist); 176 + seq_printf(m, 177 + "0x%x 0x%llx 0x%x %d %d %d %s", 178 + tcon->tid, 179 + cfile->fid.persistent_fid, 180 + cfile->f_flags, 181 + cfile->count, 182 + cfile->pid, 183 + from_kuid(&init_user_ns, cfile->uid), 184 + cfile->dentry->d_name.name); 185 + #ifdef CONFIG_CIFS_DEBUG2 186 + seq_printf(m, " 0x%llx\n", cfile->fid.mid); 187 + #else 188 + seq_printf(m, "\n"); 189 + #endif /* CIFS_DEBUG2 */ 190 + } 191 + spin_unlock(&tcon->open_file_lock); 192 + } 193 + } 194 + } 195 + spin_unlock(&cifs_tcp_ses_lock); 196 + seq_putc(m, '\n'); 197 + return 0; 198 + } 199 + 148 200 static int cifs_debug_data_proc_show(struct seq_file *m, void *v) 149 201 { 150 202 struct list_head *tmp1, *tmp2, *tmp3; ··· 617 565 proc_create_single("DebugData", 0, proc_fs_cifs, 618 566 cifs_debug_data_proc_show); 619 567 568 + proc_create_single("open_files", 0400, proc_fs_cifs, 569 + cifs_debug_files_proc_show); 570 + 620 571 proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops); 621 572 proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops); 622 573 proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops); ··· 656 601 return; 657 602 658 603 remove_proc_entry("DebugData", proc_fs_cifs); 604 + remove_proc_entry("open_files", proc_fs_cifs); 659 605 remove_proc_entry("cifsFYI", proc_fs_cifs); 660 606 remove_proc_entry("traceSMB", proc_fs_cifs); 661 607 remove_proc_entry("Stats", proc_fs_cifs);
+4 -2
fs/cifs/cifs_spnego.c
··· 147 147 sprintf(dp, ";sec=krb5"); 148 148 else if (server->sec_mskerberos) 149 149 sprintf(dp, ";sec=mskrb5"); 150 - else 151 - goto out; 150 + else { 151 + cifs_dbg(VFS, "unknown or missing server auth type, use krb5\n"); 152 + sprintf(dp, ";sec=krb5"); 153 + } 152 154 153 155 dp = description + strlen(description); 154 156 sprintf(dp, ";uid=0x%x",
+9 -8
fs/cifs/cifsfs.c
··· 999 999 struct inode *src_inode = file_inode(src_file); 1000 1000 struct inode *target_inode = file_inode(dst_file); 1001 1001 struct cifsFileInfo *smb_file_src = src_file->private_data; 1002 - struct cifsFileInfo *smb_file_target = dst_file->private_data; 1003 - struct cifs_tcon *target_tcon = tlink_tcon(smb_file_target->tlink); 1002 + struct cifsFileInfo *smb_file_target; 1003 + struct cifs_tcon *target_tcon; 1004 1004 unsigned int xid; 1005 1005 int rc; 1006 1006 ··· 1016 1016 cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n"); 1017 1017 goto out; 1018 1018 } 1019 + 1020 + smb_file_target = dst_file->private_data; 1021 + target_tcon = tlink_tcon(smb_file_target->tlink); 1019 1022 1020 1023 /* 1021 1024 * Note: cifs case is easier than btrfs since server responsible for ··· 1183 1180 }; 1184 1181 1185 1182 const struct file_operations cifs_file_direct_ops = { 1186 - /* BB reevaluate whether they can be done with directio, no cache */ 1187 - .read_iter = cifs_user_readv, 1188 - .write_iter = cifs_user_writev, 1183 + .read_iter = cifs_direct_readv, 1184 + .write_iter = cifs_direct_writev, 1189 1185 .open = cifs_open, 1190 1186 .release = cifs_close, 1191 1187 .lock = cifs_lock, ··· 1238 1236 }; 1239 1237 1240 1238 const struct file_operations cifs_file_direct_nobrl_ops = { 1241 - /* BB reevaluate whether they can be done with directio, no cache */ 1242 - .read_iter = cifs_user_readv, 1243 - .write_iter = cifs_user_writev, 1239 + .read_iter = cifs_direct_readv, 1240 + .write_iter = cifs_direct_writev, 1244 1241 .open = cifs_open, 1245 1242 .release = cifs_close, 1246 1243 .fsync = cifs_fsync,
+2
fs/cifs/cifsfs.h
··· 101 101 extern int cifs_close(struct inode *inode, struct file *file); 102 102 extern int cifs_closedir(struct inode *inode, struct file *file); 103 103 extern ssize_t cifs_user_readv(struct kiocb *iocb, struct iov_iter *to); 104 + extern ssize_t cifs_direct_readv(struct kiocb *iocb, struct iov_iter *to); 104 105 extern ssize_t cifs_strict_readv(struct kiocb *iocb, struct iov_iter *to); 105 106 extern ssize_t cifs_user_writev(struct kiocb *iocb, struct iov_iter *from); 107 + extern ssize_t cifs_direct_writev(struct kiocb *iocb, struct iov_iter *from); 106 108 extern ssize_t cifs_strict_writev(struct kiocb *iocb, struct iov_iter *from); 107 109 extern int cifs_lock(struct file *, int, struct file_lock *); 108 110 extern int cifs_fsync(struct file *, loff_t, loff_t, int);
+8
fs/cifs/cifsglob.h
··· 1125 1125 __u8 create_guid[16]; 1126 1126 struct cifs_pending_open *pending_open; 1127 1127 unsigned int epoch; 1128 + #ifdef CONFIG_CIFS_DEBUG2 1129 + __u64 mid; 1130 + #endif /* CIFS_DEBUG2 */ 1128 1131 bool purge_cache; 1129 1132 }; 1130 1133 ··· 1186 1183 unsigned int len; 1187 1184 unsigned int total_len; 1188 1185 bool should_dirty; 1186 + /* 1187 + * Indicates if this aio_ctx is for direct_io, 1188 + * If yes, iter is a copy of the user passed iov_iter 1189 + */ 1190 + bool direct_io; 1189 1191 }; 1190 1192 1191 1193 struct cifs_readdata;
+3
fs/cifs/cifspdu.h
··· 1539 1539 char PathBuffer[0]; 1540 1540 } __attribute__((packed)); 1541 1541 1542 + /* Flag above */ 1543 + #define SYMLINK_FLAG_RELATIVE 0x00000001 1544 + 1542 1545 /* For IO_REPARSE_TAG_NFS */ 1543 1546 #define NFS_SPECFILE_LNK 0x00000000014B4E4C 1544 1547 #define NFS_SPECFILE_CHR 0x0000000000524843
+355 -81
fs/cifs/file.c
··· 1005 1005 * Set the byte-range lock (mandatory style). Returns: 1006 1006 * 1) 0, if we set the lock and don't need to request to the server; 1007 1007 * 2) 1, if no locks prevent us but we need to request to the server; 1008 - * 3) -EACCESS, if there is a lock that prevents us and wait is false. 1008 + * 3) -EACCES, if there is a lock that prevents us and wait is false. 1009 1009 */ 1010 1010 static int 1011 1011 cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock, ··· 2538 2538 } 2539 2539 2540 2540 static int 2541 + cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list, 2542 + struct cifs_aio_ctx *ctx) 2543 + { 2544 + int wait_retry = 0; 2545 + unsigned int wsize, credits; 2546 + int rc; 2547 + struct TCP_Server_Info *server = 2548 + tlink_tcon(wdata->cfile->tlink)->ses->server; 2549 + 2550 + /* 2551 + * Try to resend this wdata, waiting for credits up to 3 seconds. 2552 + * Note: we are attempting to resend the whole wdata not in segments 2553 + */ 2554 + do { 2555 + rc = server->ops->wait_mtu_credits( 2556 + server, wdata->bytes, &wsize, &credits); 2557 + 2558 + if (rc) 2559 + break; 2560 + 2561 + if (wsize < wdata->bytes) { 2562 + add_credits_and_wake_if(server, credits, 0); 2563 + msleep(1000); 2564 + wait_retry++; 2565 + } 2566 + } while (wsize < wdata->bytes && wait_retry < 3); 2567 + 2568 + if (wsize < wdata->bytes) { 2569 + rc = -EBUSY; 2570 + goto out; 2571 + } 2572 + 2573 + rc = -EAGAIN; 2574 + while (rc == -EAGAIN) { 2575 + rc = 0; 2576 + if (wdata->cfile->invalidHandle) 2577 + rc = cifs_reopen_file(wdata->cfile, false); 2578 + if (!rc) 2579 + rc = server->ops->async_writev(wdata, 2580 + cifs_uncached_writedata_release); 2581 + } 2582 + 2583 + if (!rc) { 2584 + list_add_tail(&wdata->list, wdata_list); 2585 + return 0; 2586 + } 2587 + 2588 + add_credits_and_wake_if(server, wdata->credits, 0); 2589 + out: 2590 + kref_put(&wdata->refcount, cifs_uncached_writedata_release); 2591 + 2592 + return rc; 2593 + } 2594 + 2595 + static int 2541 2596 cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, 2542 2597 struct cifsFileInfo *open_file, 2543 2598 struct cifs_sb_info *cifs_sb, struct list_head *wdata_list, ··· 2606 2551 loff_t saved_offset = offset; 2607 2552 pid_t pid; 2608 2553 struct TCP_Server_Info *server; 2554 + struct page **pagevec; 2555 + size_t start; 2609 2556 2610 2557 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) 2611 2558 pid = open_file->pid; ··· 2624 2567 if (rc) 2625 2568 break; 2626 2569 2627 - nr_pages = get_numpages(wsize, len, &cur_len); 2628 - wdata = cifs_writedata_alloc(nr_pages, 2570 + if (ctx->direct_io) { 2571 + ssize_t result; 2572 + 2573 + result = iov_iter_get_pages_alloc( 2574 + from, &pagevec, wsize, &start); 2575 + if (result < 0) { 2576 + cifs_dbg(VFS, 2577 + "direct_writev couldn't get user pages " 2578 + "(rc=%zd) iter type %d iov_offset %zd " 2579 + "count %zd\n", 2580 + result, from->type, 2581 + from->iov_offset, from->count); 2582 + dump_stack(); 2583 + break; 2584 + } 2585 + cur_len = (size_t)result; 2586 + iov_iter_advance(from, cur_len); 2587 + 2588 + nr_pages = 2589 + (cur_len + start + PAGE_SIZE - 1) / PAGE_SIZE; 2590 + 2591 + wdata = cifs_writedata_direct_alloc(pagevec, 2629 2592 cifs_uncached_writev_complete); 2630 - if (!wdata) { 2631 - rc = -ENOMEM; 2632 - add_credits_and_wake_if(server, credits, 0); 2633 - break; 2634 - } 2593 + if (!wdata) { 2594 + rc = -ENOMEM; 2595 + add_credits_and_wake_if(server, credits, 0); 2596 + break; 2597 + } 2635 2598 2636 - rc = cifs_write_allocate_pages(wdata->pages, nr_pages); 2637 - if (rc) { 2638 - kfree(wdata); 2639 - add_credits_and_wake_if(server, credits, 0); 2640 - break; 2641 - } 2642 2599 2643 - num_pages = nr_pages; 2644 - rc = wdata_fill_from_iovec(wdata, from, &cur_len, &num_pages); 2645 - if (rc) { 2646 - for (i = 0; i < nr_pages; i++) 2647 - put_page(wdata->pages[i]); 2648 - kfree(wdata); 2649 - add_credits_and_wake_if(server, credits, 0); 2650 - break; 2651 - } 2600 + wdata->page_offset = start; 2601 + wdata->tailsz = 2602 + nr_pages > 1 ? 2603 + cur_len - (PAGE_SIZE - start) - 2604 + (nr_pages - 2) * PAGE_SIZE : 2605 + cur_len; 2606 + } else { 2607 + nr_pages = get_numpages(wsize, len, &cur_len); 2608 + wdata = cifs_writedata_alloc(nr_pages, 2609 + cifs_uncached_writev_complete); 2610 + if (!wdata) { 2611 + rc = -ENOMEM; 2612 + add_credits_and_wake_if(server, credits, 0); 2613 + break; 2614 + } 2652 2615 2653 - /* 2654 - * Bring nr_pages down to the number of pages we actually used, 2655 - * and free any pages that we didn't use. 2656 - */ 2657 - for ( ; nr_pages > num_pages; nr_pages--) 2658 - put_page(wdata->pages[nr_pages - 1]); 2616 + rc = cifs_write_allocate_pages(wdata->pages, nr_pages); 2617 + if (rc) { 2618 + kfree(wdata); 2619 + add_credits_and_wake_if(server, credits, 0); 2620 + break; 2621 + } 2622 + 2623 + num_pages = nr_pages; 2624 + rc = wdata_fill_from_iovec( 2625 + wdata, from, &cur_len, &num_pages); 2626 + if (rc) { 2627 + for (i = 0; i < nr_pages; i++) 2628 + put_page(wdata->pages[i]); 2629 + kfree(wdata); 2630 + add_credits_and_wake_if(server, credits, 0); 2631 + break; 2632 + } 2633 + 2634 + /* 2635 + * Bring nr_pages down to the number of pages we 2636 + * actually used, and free any pages that we didn't use. 2637 + */ 2638 + for ( ; nr_pages > num_pages; nr_pages--) 2639 + put_page(wdata->pages[nr_pages - 1]); 2640 + 2641 + wdata->tailsz = cur_len - ((nr_pages - 1) * PAGE_SIZE); 2642 + } 2659 2643 2660 2644 wdata->sync_mode = WB_SYNC_ALL; 2661 2645 wdata->nr_pages = nr_pages; ··· 2705 2607 wdata->pid = pid; 2706 2608 wdata->bytes = cur_len; 2707 2609 wdata->pagesz = PAGE_SIZE; 2708 - wdata->tailsz = cur_len - ((nr_pages - 1) * PAGE_SIZE); 2709 2610 wdata->credits = credits; 2710 2611 wdata->ctx = ctx; 2711 2612 kref_get(&ctx->refcount); ··· 2779 2682 INIT_LIST_HEAD(&tmp_list); 2780 2683 list_del_init(&wdata->list); 2781 2684 2782 - iov_iter_advance(&tmp_from, 2685 + if (ctx->direct_io) 2686 + rc = cifs_resend_wdata( 2687 + wdata, &tmp_list, ctx); 2688 + else { 2689 + iov_iter_advance(&tmp_from, 2783 2690 wdata->offset - ctx->pos); 2784 2691 2785 - rc = cifs_write_from_iter(wdata->offset, 2692 + rc = cifs_write_from_iter(wdata->offset, 2786 2693 wdata->bytes, &tmp_from, 2787 2694 ctx->cfile, cifs_sb, &tmp_list, 2788 2695 ctx); 2696 + } 2789 2697 2790 2698 list_splice(&tmp_list, &ctx->list); 2791 2699 ··· 2803 2701 kref_put(&wdata->refcount, cifs_uncached_writedata_release); 2804 2702 } 2805 2703 2806 - for (i = 0; i < ctx->npages; i++) 2807 - put_page(ctx->bv[i].bv_page); 2704 + if (!ctx->direct_io) 2705 + for (i = 0; i < ctx->npages; i++) 2706 + put_page(ctx->bv[i].bv_page); 2808 2707 2809 2708 cifs_stats_bytes_written(tcon, ctx->total_len); 2810 2709 set_bit(CIFS_INO_INVALID_MAPPING, &CIFS_I(dentry->d_inode)->flags); ··· 2820 2717 complete(&ctx->done); 2821 2718 } 2822 2719 2823 - ssize_t cifs_user_writev(struct kiocb *iocb, struct iov_iter *from) 2720 + static ssize_t __cifs_writev( 2721 + struct kiocb *iocb, struct iov_iter *from, bool direct) 2824 2722 { 2825 2723 struct file *file = iocb->ki_filp; 2826 2724 ssize_t total_written = 0; ··· 2830 2726 struct cifs_sb_info *cifs_sb; 2831 2727 struct cifs_aio_ctx *ctx; 2832 2728 struct iov_iter saved_from = *from; 2729 + size_t len = iov_iter_count(from); 2833 2730 int rc; 2834 2731 2835 2732 /* 2836 - * BB - optimize the way when signing is disabled. We can drop this 2837 - * extra memory-to-memory copying and use iovec buffers for constructing 2838 - * write request. 2733 + * iov_iter_get_pages_alloc doesn't work with ITER_KVEC. 2734 + * In this case, fall back to non-direct write function. 2735 + * this could be improved by getting pages directly in ITER_KVEC 2839 2736 */ 2737 + if (direct && from->type & ITER_KVEC) { 2738 + cifs_dbg(FYI, "use non-direct cifs_writev for kvec I/O\n"); 2739 + direct = false; 2740 + } 2840 2741 2841 2742 rc = generic_write_checks(iocb, from); 2842 2743 if (rc <= 0) ··· 2865 2756 2866 2757 ctx->pos = iocb->ki_pos; 2867 2758 2868 - rc = setup_aio_ctx_iter(ctx, from, WRITE); 2869 - if (rc) { 2870 - kref_put(&ctx->refcount, cifs_aio_ctx_release); 2871 - return rc; 2759 + if (direct) { 2760 + ctx->direct_io = true; 2761 + ctx->iter = *from; 2762 + ctx->len = len; 2763 + } else { 2764 + rc = setup_aio_ctx_iter(ctx, from, WRITE); 2765 + if (rc) { 2766 + kref_put(&ctx->refcount, cifs_aio_ctx_release); 2767 + return rc; 2768 + } 2872 2769 } 2873 2770 2874 2771 /* grab a lock here due to read response handlers can access ctx */ ··· 2922 2807 2923 2808 iocb->ki_pos += total_written; 2924 2809 return total_written; 2810 + } 2811 + 2812 + ssize_t cifs_direct_writev(struct kiocb *iocb, struct iov_iter *from) 2813 + { 2814 + return __cifs_writev(iocb, from, true); 2815 + } 2816 + 2817 + ssize_t cifs_user_writev(struct kiocb *iocb, struct iov_iter *from) 2818 + { 2819 + return __cifs_writev(iocb, from, false); 2925 2820 } 2926 2821 2927 2822 static ssize_t ··· 3104 2979 kref_put(&rdata->ctx->refcount, cifs_aio_ctx_release); 3105 2980 for (i = 0; i < rdata->nr_pages; i++) { 3106 2981 put_page(rdata->pages[i]); 3107 - rdata->pages[i] = NULL; 3108 2982 } 3109 2983 cifs_readdata_release(refcount); 3110 2984 } ··· 3230 3106 return uncached_fill_pages(server, rdata, iter, iter->count); 3231 3107 } 3232 3108 3109 + static int cifs_resend_rdata(struct cifs_readdata *rdata, 3110 + struct list_head *rdata_list, 3111 + struct cifs_aio_ctx *ctx) 3112 + { 3113 + int wait_retry = 0; 3114 + unsigned int rsize, credits; 3115 + int rc; 3116 + struct TCP_Server_Info *server = 3117 + tlink_tcon(rdata->cfile->tlink)->ses->server; 3118 + 3119 + /* 3120 + * Try to resend this rdata, waiting for credits up to 3 seconds. 3121 + * Note: we are attempting to resend the whole rdata not in segments 3122 + */ 3123 + do { 3124 + rc = server->ops->wait_mtu_credits(server, rdata->bytes, 3125 + &rsize, &credits); 3126 + 3127 + if (rc) 3128 + break; 3129 + 3130 + if (rsize < rdata->bytes) { 3131 + add_credits_and_wake_if(server, credits, 0); 3132 + msleep(1000); 3133 + wait_retry++; 3134 + } 3135 + } while (rsize < rdata->bytes && wait_retry < 3); 3136 + 3137 + /* 3138 + * If we can't find enough credits to send this rdata 3139 + * release the rdata and return failure, this will pass 3140 + * whatever I/O amount we have finished to VFS. 3141 + */ 3142 + if (rsize < rdata->bytes) { 3143 + rc = -EBUSY; 3144 + goto out; 3145 + } 3146 + 3147 + rc = -EAGAIN; 3148 + while (rc == -EAGAIN) { 3149 + rc = 0; 3150 + if (rdata->cfile->invalidHandle) 3151 + rc = cifs_reopen_file(rdata->cfile, true); 3152 + if (!rc) 3153 + rc = server->ops->async_readv(rdata); 3154 + } 3155 + 3156 + if (!rc) { 3157 + /* Add to aio pending list */ 3158 + list_add_tail(&rdata->list, rdata_list); 3159 + return 0; 3160 + } 3161 + 3162 + add_credits_and_wake_if(server, rdata->credits, 0); 3163 + out: 3164 + kref_put(&rdata->refcount, 3165 + cifs_uncached_readdata_release); 3166 + 3167 + return rc; 3168 + } 3169 + 3233 3170 static int 3234 3171 cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, 3235 3172 struct cifs_sb_info *cifs_sb, struct list_head *rdata_list, ··· 3302 3117 int rc; 3303 3118 pid_t pid; 3304 3119 struct TCP_Server_Info *server; 3120 + struct page **pagevec; 3121 + size_t start; 3122 + struct iov_iter direct_iov = ctx->iter; 3305 3123 3306 3124 server = tlink_tcon(open_file->tlink)->ses->server; 3307 3125 ··· 3313 3125 else 3314 3126 pid = current->tgid; 3315 3127 3128 + if (ctx->direct_io) 3129 + iov_iter_advance(&direct_iov, offset - ctx->pos); 3130 + 3316 3131 do { 3317 3132 rc = server->ops->wait_mtu_credits(server, cifs_sb->rsize, 3318 3133 &rsize, &credits); ··· 3323 3132 break; 3324 3133 3325 3134 cur_len = min_t(const size_t, len, rsize); 3326 - npages = DIV_ROUND_UP(cur_len, PAGE_SIZE); 3327 3135 3328 - /* allocate a readdata struct */ 3329 - rdata = cifs_readdata_alloc(npages, 3136 + if (ctx->direct_io) { 3137 + ssize_t result; 3138 + 3139 + result = iov_iter_get_pages_alloc( 3140 + &direct_iov, &pagevec, 3141 + cur_len, &start); 3142 + if (result < 0) { 3143 + cifs_dbg(VFS, 3144 + "couldn't get user pages (cur_len=%zd)" 3145 + " iter type %d" 3146 + " iov_offset %zd count %zd\n", 3147 + result, direct_iov.type, 3148 + direct_iov.iov_offset, 3149 + direct_iov.count); 3150 + dump_stack(); 3151 + break; 3152 + } 3153 + cur_len = (size_t)result; 3154 + iov_iter_advance(&direct_iov, cur_len); 3155 + 3156 + rdata = cifs_readdata_direct_alloc( 3157 + pagevec, cifs_uncached_readv_complete); 3158 + if (!rdata) { 3159 + add_credits_and_wake_if(server, credits, 0); 3160 + rc = -ENOMEM; 3161 + break; 3162 + } 3163 + 3164 + npages = (cur_len + start + PAGE_SIZE-1) / PAGE_SIZE; 3165 + rdata->page_offset = start; 3166 + rdata->tailsz = npages > 1 ? 3167 + cur_len-(PAGE_SIZE-start)-(npages-2)*PAGE_SIZE : 3168 + cur_len; 3169 + 3170 + } else { 3171 + 3172 + npages = DIV_ROUND_UP(cur_len, PAGE_SIZE); 3173 + /* allocate a readdata struct */ 3174 + rdata = cifs_readdata_alloc(npages, 3330 3175 cifs_uncached_readv_complete); 3331 - if (!rdata) { 3332 - add_credits_and_wake_if(server, credits, 0); 3333 - rc = -ENOMEM; 3334 - break; 3335 - } 3176 + if (!rdata) { 3177 + add_credits_and_wake_if(server, credits, 0); 3178 + rc = -ENOMEM; 3179 + break; 3180 + } 3336 3181 3337 - rc = cifs_read_allocate_pages(rdata, npages); 3338 - if (rc) 3339 - goto error; 3182 + rc = cifs_read_allocate_pages(rdata, npages); 3183 + if (rc) 3184 + goto error; 3185 + 3186 + rdata->tailsz = PAGE_SIZE; 3187 + } 3340 3188 3341 3189 rdata->cfile = cifsFileInfo_get(open_file); 3342 3190 rdata->nr_pages = npages; ··· 3383 3153 rdata->bytes = cur_len; 3384 3154 rdata->pid = pid; 3385 3155 rdata->pagesz = PAGE_SIZE; 3386 - rdata->tailsz = PAGE_SIZE; 3387 3156 rdata->read_into_pages = cifs_uncached_read_into_pages; 3388 3157 rdata->copy_into_pages = cifs_uncached_copy_into_pages; 3389 3158 rdata->credits = credits; ··· 3396 3167 if (rc) { 3397 3168 add_credits_and_wake_if(server, rdata->credits, 0); 3398 3169 kref_put(&rdata->refcount, 3399 - cifs_uncached_readdata_release); 3400 - if (rc == -EAGAIN) 3170 + cifs_uncached_readdata_release); 3171 + if (rc == -EAGAIN) { 3172 + iov_iter_revert(&direct_iov, cur_len); 3401 3173 continue; 3174 + } 3402 3175 break; 3403 3176 } 3404 3177 ··· 3456 3225 * reading. 3457 3226 */ 3458 3227 if (got_bytes && got_bytes < rdata->bytes) { 3459 - rc = cifs_readdata_to_iov(rdata, to); 3228 + rc = 0; 3229 + if (!ctx->direct_io) 3230 + rc = cifs_readdata_to_iov(rdata, to); 3460 3231 if (rc) { 3461 3232 kref_put(&rdata->refcount, 3462 - cifs_uncached_readdata_release); 3233 + cifs_uncached_readdata_release); 3463 3234 continue; 3464 3235 } 3465 3236 } 3466 3237 3467 - rc = cifs_send_async_read( 3238 + if (ctx->direct_io) { 3239 + /* 3240 + * Re-use rdata as this is a 3241 + * direct I/O 3242 + */ 3243 + rc = cifs_resend_rdata( 3244 + rdata, 3245 + &tmp_list, ctx); 3246 + } else { 3247 + rc = cifs_send_async_read( 3468 3248 rdata->offset + got_bytes, 3469 3249 rdata->bytes - got_bytes, 3470 3250 rdata->cfile, cifs_sb, 3471 3251 &tmp_list, ctx); 3472 3252 3253 + kref_put(&rdata->refcount, 3254 + cifs_uncached_readdata_release); 3255 + } 3256 + 3473 3257 list_splice(&tmp_list, &ctx->list); 3474 3258 3475 - kref_put(&rdata->refcount, 3476 - cifs_uncached_readdata_release); 3477 3259 goto again; 3478 3260 } else if (rdata->result) 3479 3261 rc = rdata->result; 3480 - else 3262 + else if (!ctx->direct_io) 3481 3263 rc = cifs_readdata_to_iov(rdata, to); 3482 3264 3483 3265 /* if there was a short read -- discard anything left */ 3484 3266 if (rdata->got_bytes && rdata->got_bytes < rdata->bytes) 3485 3267 rc = -ENODATA; 3268 + 3269 + ctx->total_len += rdata->got_bytes; 3486 3270 } 3487 3271 list_del_init(&rdata->list); 3488 3272 kref_put(&rdata->refcount, cifs_uncached_readdata_release); 3489 3273 } 3490 3274 3491 - for (i = 0; i < ctx->npages; i++) { 3492 - if (ctx->should_dirty) 3493 - set_page_dirty(ctx->bv[i].bv_page); 3494 - put_page(ctx->bv[i].bv_page); 3495 - } 3275 + if (!ctx->direct_io) { 3276 + for (i = 0; i < ctx->npages; i++) { 3277 + if (ctx->should_dirty) 3278 + set_page_dirty(ctx->bv[i].bv_page); 3279 + put_page(ctx->bv[i].bv_page); 3280 + } 3496 3281 3497 - ctx->total_len = ctx->len - iov_iter_count(to); 3282 + ctx->total_len = ctx->len - iov_iter_count(to); 3283 + } 3498 3284 3499 3285 cifs_stats_bytes_read(tcon, ctx->total_len); 3500 3286 ··· 3529 3281 complete(&ctx->done); 3530 3282 } 3531 3283 3532 - ssize_t cifs_user_readv(struct kiocb *iocb, struct iov_iter *to) 3284 + static ssize_t __cifs_readv( 3285 + struct kiocb *iocb, struct iov_iter *to, bool direct) 3533 3286 { 3534 - struct file *file = iocb->ki_filp; 3535 - ssize_t rc; 3536 3287 size_t len; 3537 - ssize_t total_read = 0; 3538 - loff_t offset = iocb->ki_pos; 3288 + struct file *file = iocb->ki_filp; 3539 3289 struct cifs_sb_info *cifs_sb; 3540 - struct cifs_tcon *tcon; 3541 3290 struct cifsFileInfo *cfile; 3291 + struct cifs_tcon *tcon; 3292 + ssize_t rc, total_read = 0; 3293 + loff_t offset = iocb->ki_pos; 3542 3294 struct cifs_aio_ctx *ctx; 3295 + 3296 + /* 3297 + * iov_iter_get_pages_alloc() doesn't work with ITER_KVEC, 3298 + * fall back to data copy read path 3299 + * this could be improved by getting pages directly in ITER_KVEC 3300 + */ 3301 + if (direct && to->type & ITER_KVEC) { 3302 + cifs_dbg(FYI, "use non-direct cifs_user_readv for kvec I/O\n"); 3303 + direct = false; 3304 + } 3543 3305 3544 3306 len = iov_iter_count(to); 3545 3307 if (!len) ··· 3577 3319 if (iter_is_iovec(to)) 3578 3320 ctx->should_dirty = true; 3579 3321 3580 - rc = setup_aio_ctx_iter(ctx, to, READ); 3581 - if (rc) { 3582 - kref_put(&ctx->refcount, cifs_aio_ctx_release); 3583 - return rc; 3322 + if (direct) { 3323 + ctx->pos = offset; 3324 + ctx->direct_io = true; 3325 + ctx->iter = *to; 3326 + ctx->len = len; 3327 + } else { 3328 + rc = setup_aio_ctx_iter(ctx, to, READ); 3329 + if (rc) { 3330 + kref_put(&ctx->refcount, cifs_aio_ctx_release); 3331 + return rc; 3332 + } 3333 + len = ctx->len; 3584 3334 } 3585 - 3586 - len = ctx->len; 3587 3335 3588 3336 /* grab a lock here due to read response handlers can access ctx */ 3589 3337 mutex_lock(&ctx->aio_mutex); ··· 3630 3366 return total_read; 3631 3367 } 3632 3368 return rc; 3369 + } 3370 + 3371 + ssize_t cifs_direct_readv(struct kiocb *iocb, struct iov_iter *to) 3372 + { 3373 + return __cifs_readv(iocb, to, true); 3374 + } 3375 + 3376 + ssize_t cifs_user_readv(struct kiocb *iocb, struct iov_iter *to) 3377 + { 3378 + return __cifs_readv(iocb, to, false); 3633 3379 } 3634 3380 3635 3381 ssize_t
+2 -2
fs/cifs/inode.c
··· 1320 1320 /* 1321 1321 * If d_inode(dentry) is null (usually meaning the cached dentry 1322 1322 * is a negative dentry) then we would attempt a standard SMB delete, but 1323 - * if that fails we can not attempt the fall back mechanisms on EACCESS 1324 - * but will return the EACCESS to the caller. Note that the VFS does not call 1323 + * if that fails we can not attempt the fall back mechanisms on EACCES 1324 + * but will return the EACCES to the caller. Note that the VFS does not call 1325 1325 * unlink on negative dentries currently. 1326 1326 */ 1327 1327 int cifs_unlink(struct inode *dir, struct dentry *dentry)
+9 -5
fs/cifs/smb2ops.c
··· 747 747 int rc = 0; 748 748 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; 749 749 char *name, *value; 750 + size_t buf_size = dst_size; 750 751 size_t name_len, value_len, user_name_len; 751 752 752 753 while (src_size > 0) { ··· 783 782 /* 'user.' plus a terminating null */ 784 783 user_name_len = 5 + 1 + name_len; 785 784 786 - rc += user_name_len; 787 - 788 - if (dst_size >= user_name_len) { 785 + if (buf_size == 0) { 786 + /* skip copy - calc size only */ 787 + rc += user_name_len; 788 + } else if (dst_size >= user_name_len) { 789 789 dst_size -= user_name_len; 790 790 memcpy(dst, "user.", 5); 791 791 dst += 5; ··· 794 792 dst += name_len; 795 793 *dst = 0; 796 794 ++dst; 797 - } else if (dst_size == 0) { 798 - /* skip copy - calc size only */ 795 + rc += user_name_len; 799 796 } else { 800 797 /* stop before overrun buffer */ 801 798 rc = -ERANGE; ··· 1079 1078 1080 1079 cfile->fid.persistent_fid = fid->persistent_fid; 1081 1080 cfile->fid.volatile_fid = fid->volatile_fid; 1081 + #ifdef CONFIG_CIFS_DEBUG2 1082 + cfile->fid.mid = fid->mid; 1083 + #endif /* CIFS_DEBUG2 */ 1082 1084 server->ops->set_oplock_level(cinode, oplock, fid->epoch, 1083 1085 &fid->purge_cache); 1084 1086 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
+5 -1
fs/cifs/smb2pdu.c
··· 1512 1512 rc = cifs_send_recv(xid, ses, &rqst, &resp_buftype, flags, &rsp_iov); 1513 1513 cifs_small_buf_release(req); 1514 1514 rsp = (struct smb2_tree_connect_rsp *)rsp_iov.iov_base; 1515 - 1515 + trace_smb3_tcon(xid, tcon->tid, ses->Suid, tree, rc); 1516 1516 if (rc != 0) { 1517 1517 if (tcon) { 1518 1518 cifs_stats_fail_inc(tcon, SMB2_TREE_CONNECT_HE); ··· 1559 1559 if (tcon->ses->server->ops->validate_negotiate) 1560 1560 rc = tcon->ses->server->ops->validate_negotiate(xid, tcon); 1561 1561 tcon_exit: 1562 + 1562 1563 free_rsp_buf(resp_buftype, rsp); 1563 1564 kfree(unc_path); 1564 1565 return rc; ··· 2309 2308 atomic_inc(&tcon->num_remote_opens); 2310 2309 oparms->fid->persistent_fid = rsp->PersistentFileId; 2311 2310 oparms->fid->volatile_fid = rsp->VolatileFileId; 2311 + #ifdef CONFIG_CIFS_DEBUG2 2312 + oparms->fid->mid = le64_to_cpu(rsp->sync_hdr.MessageId); 2313 + #endif /* CIFS_DEBUG2 */ 2312 2314 2313 2315 if (buf) { 2314 2316 memcpy(buf, &rsp->CreationTime, 32);
+35
fs/cifs/smb2pdu.h
··· 842 842 /* Integrity flags for above */ 843 843 #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001 844 844 845 + /* Reparse structures - see MS-FSCC 2.1.2 */ 846 + 847 + /* struct fsctl_reparse_info_req is empty, only response structs (see below) */ 848 + 849 + struct reparse_data_buffer { 850 + __le32 ReparseTag; 851 + __le16 ReparseDataLength; 852 + __u16 Reserved; 853 + __u8 DataBuffer[0]; /* Variable Length */ 854 + } __packed; 855 + 856 + struct reparse_guid_data_buffer { 857 + __le32 ReparseTag; 858 + __le16 ReparseDataLength; 859 + __u16 Reserved; 860 + __u8 ReparseGuid[16]; 861 + __u8 DataBuffer[0]; /* Variable Length */ 862 + } __packed; 863 + 864 + struct reparse_mount_point_data_buffer { 865 + __le32 ReparseTag; 866 + __le16 ReparseDataLength; 867 + __u16 Reserved; 868 + __le16 SubstituteNameOffset; 869 + __le16 SubstituteNameLength; 870 + __le16 PrintNameOffset; 871 + __le16 PrintNameLength; 872 + __u8 PathBuffer[0]; /* Variable Length */ 873 + } __packed; 874 + 875 + /* See MS-FSCC 2.1.2.4 and cifspdu.h for struct reparse_symlink_data */ 876 + 877 + /* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */ 878 + 879 + 845 880 /* See MS-DFSC 2.2.2 */ 846 881 struct fsctl_get_dfs_referral_req { 847 882 __le16 MaxReferralLevel;
+42
fs/cifs/trace.h
··· 374 374 DEFINE_SMB3_ENTER_EXIT_EVENT(exit_done); 375 375 376 376 /* 377 + * For SMB2/SMB3 tree connect 378 + */ 379 + 380 + DECLARE_EVENT_CLASS(smb3_tcon_class, 381 + TP_PROTO(unsigned int xid, 382 + __u32 tid, 383 + __u64 sesid, 384 + const char *unc_name, 385 + int rc), 386 + TP_ARGS(xid, tid, sesid, unc_name, rc), 387 + TP_STRUCT__entry( 388 + __field(unsigned int, xid) 389 + __field(__u32, tid) 390 + __field(__u64, sesid) 391 + __field(const char *, unc_name) 392 + __field(int, rc) 393 + ), 394 + TP_fast_assign( 395 + __entry->xid = xid; 396 + __entry->tid = tid; 397 + __entry->sesid = sesid; 398 + __entry->unc_name = unc_name; 399 + __entry->rc = rc; 400 + ), 401 + TP_printk("xid=%u sid=0x%llx tid=0x%x unc_name=%s rc=%d", 402 + __entry->xid, __entry->sesid, __entry->tid, 403 + __entry->unc_name, __entry->rc) 404 + ) 405 + 406 + #define DEFINE_SMB3_TCON_EVENT(name) \ 407 + DEFINE_EVENT(smb3_tcon_class, smb3_##name, \ 408 + TP_PROTO(unsigned int xid, \ 409 + __u32 tid, \ 410 + __u64 sesid, \ 411 + const char *unc_name, \ 412 + int rc), \ 413 + TP_ARGS(xid, tid, sesid, unc_name, rc)) 414 + 415 + DEFINE_SMB3_TCON_EVENT(tcon); 416 + 417 + 418 + /* 377 419 * For smb2/smb3 open call 378 420 */ 379 421 DECLARE_EVENT_CLASS(smb3_open_err_class,