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

cifs: change SMB2_OP_RENAME and SMB2_OP_HARDLINK to use compounding

Get rid of smb2_open_op_close() as all operations are now migrated
to smb2_compound_op().

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>

authored by

Ronnie Sahlberg and committed by
Steve French
bb435512 3764cbd1

+60 -142
+1 -1
fs/cifs/smb2glob.h
··· 33 33 34 34 /* 35 35 * Identifiers for functions that use the open, operation, close pattern 36 - * in smb2inode.c:smb2_open_op_close() 36 + * in smb2inode.c:smb2_compound_op() 37 37 */ 38 38 #define SMB2_OP_SET_DELETE 1 39 39 #define SMB2_OP_SET_INFO 2
+59 -71
fs/cifs/smb2inode.c
··· 56 56 struct kvec rsp_iov[3]; 57 57 struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; 58 58 struct kvec qi_iov[1]; 59 - struct kvec si_iov[2]; /* 1 + potential padding. */ 59 + struct kvec si_iov[3]; /* 2 + potential padding. */ 60 60 struct kvec close_iov[1]; 61 61 struct smb2_query_info_rsp *qi_rsp = NULL; 62 62 int flags = 0; 63 63 __u8 delete_pending[8] = {1, 0, 0, 0, 0, 0, 0, 0}; 64 - unsigned int size[1]; 65 - void *data[1]; 64 + unsigned int size[2]; 65 + void *data[2]; 66 + struct smb2_file_rename_info rename_info; 67 + struct smb2_file_link_info link_info; 68 + int len; 66 69 67 70 if (smb3_encryption_required(tcon)) 68 71 flags |= CIFS_TRANSFORM_REQ; ··· 155 152 rqst[num_rqst].rq_iov = si_iov; 156 153 rqst[num_rqst].rq_nvec = 1; 157 154 155 + 158 156 size[0] = sizeof(FILE_BASIC_INFO); 159 157 data[0] = ptr; 160 158 161 159 rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, 162 160 COMPOUND_FID, current->tgid, 163 161 FILE_BASIC_INFORMATION, 162 + SMB2_O_INFO_FILE, 0, data, size); 163 + smb2_set_next_command(server, &rqst[num_rqst]); 164 + smb2_set_related(&rqst[num_rqst++]); 165 + break; 166 + case SMB2_OP_RENAME: 167 + memset(&si_iov, 0, sizeof(si_iov)); 168 + rqst[num_rqst].rq_iov = si_iov; 169 + rqst[num_rqst].rq_nvec = 2; 170 + 171 + len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX)); 172 + 173 + rename_info.ReplaceIfExists = 1; 174 + rename_info.RootDirectory = 0; 175 + rename_info.FileNameLength = cpu_to_le32(len); 176 + 177 + size[0] = sizeof(struct smb2_file_rename_info); 178 + data[0] = &rename_info; 179 + 180 + size[1] = len + 2 /* null */; 181 + data[1] = (__le16 *)ptr; 182 + 183 + rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, 184 + COMPOUND_FID, current->tgid, 185 + FILE_RENAME_INFORMATION, 186 + SMB2_O_INFO_FILE, 0, data, size); 187 + smb2_set_next_command(server, &rqst[num_rqst]); 188 + smb2_set_related(&rqst[num_rqst++]); 189 + break; 190 + case SMB2_OP_HARDLINK: 191 + memset(&si_iov, 0, sizeof(si_iov)); 192 + rqst[num_rqst].rq_iov = si_iov; 193 + rqst[num_rqst].rq_nvec = 2; 194 + 195 + len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX)); 196 + 197 + link_info.ReplaceIfExists = 0; 198 + link_info.RootDirectory = 0; 199 + link_info.FileNameLength = cpu_to_le32(len); 200 + 201 + size[0] = sizeof(struct smb2_file_link_info); 202 + data[0] = &link_info; 203 + 204 + size[1] = len + 2 /* null */; 205 + data[1] = (__le16 *)ptr; 206 + 207 + rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, 208 + COMPOUND_FID, current->tgid, 209 + FILE_LINK_INFORMATION, 164 210 SMB2_O_INFO_FILE, 0, data, size); 165 211 smb2_set_next_command(server, &rqst[num_rqst]); 166 212 smb2_set_related(&rqst[num_rqst++]); ··· 257 205 if (rqst[1].rq_iov) 258 206 SMB2_close_free(&rqst[1]); 259 207 break; 208 + case SMB2_OP_HARDLINK: 209 + case SMB2_OP_RENAME: 260 210 case SMB2_OP_RMDIR: 261 211 case SMB2_OP_SET_EOF: 262 212 case SMB2_OP_SET_INFO: ··· 271 217 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); 272 218 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); 273 219 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); 274 - return rc; 275 - } 276 - 277 - static int 278 - smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, 279 - struct cifs_sb_info *cifs_sb, const char *full_path, 280 - __u32 desired_access, __u32 create_disposition, 281 - __u32 create_options, void *data, int command) 282 - { 283 - int rc, tmprc = 0; 284 - __le16 *utf16_path = NULL; 285 - __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; 286 - struct cifs_open_parms oparms; 287 - struct cifs_fid fid; 288 - bool use_cached_root_handle = false; 289 - 290 - if ((strcmp(full_path, "") == 0) && (create_options == 0) && 291 - (desired_access == FILE_READ_ATTRIBUTES) && 292 - (create_disposition == FILE_OPEN) && 293 - (tcon->nohandlecache == false)) { 294 - rc = open_shroot(xid, tcon, &fid); 295 - if (rc == 0) 296 - use_cached_root_handle = true; 297 - } 298 - 299 - if (use_cached_root_handle == false) { 300 - utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); 301 - if (!utf16_path) 302 - return -ENOMEM; 303 - 304 - oparms.tcon = tcon; 305 - oparms.desired_access = desired_access; 306 - oparms.disposition = create_disposition; 307 - oparms.create_options = create_options; 308 - oparms.fid = &fid; 309 - oparms.reconnect = false; 310 - 311 - rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, 312 - NULL); 313 - if (rc) { 314 - kfree(utf16_path); 315 - return rc; 316 - } 317 - } 318 - 319 - switch (command) { 320 - case SMB2_OP_RENAME: 321 - tmprc = SMB2_rename(xid, tcon, fid.persistent_fid, 322 - fid.volatile_fid, (__le16 *)data); 323 - break; 324 - case SMB2_OP_HARDLINK: 325 - tmprc = SMB2_set_hardlink(xid, tcon, fid.persistent_fid, 326 - fid.volatile_fid, (__le16 *)data); 327 - break; 328 - default: 329 - cifs_dbg(VFS, "Invalid command\n"); 330 - break; 331 - } 332 - 333 - if (use_cached_root_handle) 334 - close_shroot(&tcon->crfid); 335 - else 336 - rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); 337 - if (tmprc) 338 - rc = tmprc; 339 - kfree(utf16_path); 340 220 return rc; 341 221 } 342 222 ··· 382 394 goto smb2_rename_path; 383 395 } 384 396 385 - rc = smb2_open_op_close(xid, tcon, cifs_sb, from_name, access, 386 - FILE_OPEN, 0, smb2_to_name, command); 397 + rc = smb2_compound_op(xid, tcon, cifs_sb, from_name, access, 398 + FILE_OPEN, 0, smb2_to_name, command); 387 399 smb2_rename_path: 388 400 kfree(smb2_to_name); 389 401 return rc;
-64
fs/cifs/smb2pdu.c
··· 3860 3860 } 3861 3861 3862 3862 int 3863 - SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon, 3864 - u64 persistent_fid, u64 volatile_fid, __le16 *target_file) 3865 - { 3866 - struct smb2_file_rename_info info; 3867 - void **data; 3868 - unsigned int size[2]; 3869 - int rc; 3870 - int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX)); 3871 - 3872 - data = kmalloc_array(2, sizeof(void *), GFP_KERNEL); 3873 - if (!data) 3874 - return -ENOMEM; 3875 - 3876 - info.ReplaceIfExists = 1; /* 1 = replace existing target with new */ 3877 - /* 0 = fail if target already exists */ 3878 - info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */ 3879 - info.FileNameLength = cpu_to_le32(len); 3880 - 3881 - data[0] = &info; 3882 - size[0] = sizeof(struct smb2_file_rename_info); 3883 - 3884 - data[1] = target_file; 3885 - size[1] = len + 2 /* null */; 3886 - 3887 - rc = send_set_info(xid, tcon, persistent_fid, volatile_fid, 3888 - current->tgid, FILE_RENAME_INFORMATION, SMB2_O_INFO_FILE, 3889 - 0, 2, data, size); 3890 - kfree(data); 3891 - return rc; 3892 - } 3893 - 3894 - int 3895 - SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon, 3896 - u64 persistent_fid, u64 volatile_fid, __le16 *target_file) 3897 - { 3898 - struct smb2_file_link_info info; 3899 - void **data; 3900 - unsigned int size[2]; 3901 - int rc; 3902 - int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX)); 3903 - 3904 - data = kmalloc_array(2, sizeof(void *), GFP_KERNEL); 3905 - if (!data) 3906 - return -ENOMEM; 3907 - 3908 - info.ReplaceIfExists = 0; /* 1 = replace existing link with new */ 3909 - /* 0 = fail if link already exists */ 3910 - info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */ 3911 - info.FileNameLength = cpu_to_le32(len); 3912 - 3913 - data[0] = &info; 3914 - size[0] = sizeof(struct smb2_file_link_info); 3915 - 3916 - data[1] = target_file; 3917 - size[1] = len + 2 /* null */; 3918 - 3919 - rc = send_set_info(xid, tcon, persistent_fid, volatile_fid, 3920 - current->tgid, FILE_LINK_INFORMATION, SMB2_O_INFO_FILE, 3921 - 0, 2, data, size); 3922 - kfree(data); 3923 - return rc; 3924 - } 3925 - 3926 - int 3927 3863 SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, 3928 3864 u64 volatile_fid, u32 pid, __le64 *eof) 3929 3865 {
-6
fs/cifs/smb2proto.h
··· 182 182 extern int SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, 183 183 u64 persistent_fid, u64 volatile_fid, int index, 184 184 struct cifs_search_info *srch_inf); 185 - extern int SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon, 186 - u64 persistent_fid, u64 volatile_fid, 187 - __le16 *target_file); 188 - extern int SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon, 189 - u64 persistent_fid, u64 volatile_fid, 190 - __le16 *target_file); 191 185 extern int SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, 192 186 u64 persistent_fid, u64 volatile_fid, u32 pid, 193 187 __le64 *eof);