Skip to content

Commit 287596c

Browse files
shirishpargaonkarkoenkooi
authored andcommitted
cifs: Include backup intent search flags during searches {try #2)
commit 2608bee upstream. As observed and suggested by Tushar Gosavi... --------- readdir calls these function to send TRANS2_FIND_FIRST and TRANS2_FIND_NEXT command to the server. The current cifs module is not specifying CIFS_SEARCH_BACKUP_SEARCH flag while sending these command when backupuid/backupgid is specified. This can be resolved by specifying CIFS_SEARCH_BACKUP_SEARCH flag. --------- Reported-and-Tested-by: Tushar Gosavi <tugosavi@in.ibm.com> Signed-off-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com> Acked-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve French <sfrench@us.ibm.com> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
1 parent 8cd0c42 commit 287596c

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

fs/cifs/cifsproto.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,13 @@ extern int CIFSTCon(unsigned int xid, struct cifs_ses *ses,
184184

185185
extern int CIFSFindFirst(const int xid, struct cifs_tcon *tcon,
186186
const char *searchName, const struct nls_table *nls_codepage,
187-
__u16 *searchHandle, struct cifs_search_info *psrch_inf,
187+
__u16 *searchHandle, __u16 search_flags,
188+
struct cifs_search_info *psrch_inf,
188189
int map, const char dirsep);
189190

190191
extern int CIFSFindNext(const int xid, struct cifs_tcon *tcon,
191-
__u16 searchHandle, struct cifs_search_info *psrch_inf);
192+
__u16 searchHandle, __u16 search_flags,
193+
struct cifs_search_info *psrch_inf);
192194

193195
extern int CIFSFindClose(const int, struct cifs_tcon *tcon,
194196
const __u16 search_handle);

fs/cifs/cifssmb.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4327,7 +4327,7 @@ int
43274327
CIFSFindFirst(const int xid, struct cifs_tcon *tcon,
43284328
const char *searchName,
43294329
const struct nls_table *nls_codepage,
4330-
__u16 *pnetfid,
4330+
__u16 *pnetfid, __u16 search_flags,
43314331
struct cifs_search_info *psrch_inf, int remap, const char dirsep)
43324332
{
43334333
/* level 257 SMB_ */
@@ -4399,8 +4399,7 @@ CIFSFindFirst(const int xid, struct cifs_tcon *tcon,
43994399
cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM |
44004400
ATTR_DIRECTORY);
44014401
pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO));
4402-
pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END |
4403-
CIFS_SEARCH_RETURN_RESUME);
4402+
pSMB->SearchFlags = cpu_to_le16(search_flags);
44044403
pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level);
44054404

44064405
/* BB what should we set StorageType to? Does it matter? BB */
@@ -4470,8 +4469,8 @@ CIFSFindFirst(const int xid, struct cifs_tcon *tcon,
44704469
return rc;
44714470
}
44724471

4473-
int CIFSFindNext(const int xid, struct cifs_tcon *tcon,
4474-
__u16 searchHandle, struct cifs_search_info *psrch_inf)
4472+
int CIFSFindNext(const int xid, struct cifs_tcon *tcon, __u16 searchHandle,
4473+
__u16 search_flags, struct cifs_search_info *psrch_inf)
44754474
{
44764475
TRANSACTION2_FNEXT_REQ *pSMB = NULL;
44774476
TRANSACTION2_FNEXT_RSP *pSMBr = NULL;
@@ -4514,8 +4513,7 @@ int CIFSFindNext(const int xid, struct cifs_tcon *tcon,
45144513
cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO));
45154514
pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level);
45164515
pSMB->ResumeKey = psrch_inf->resume_key;
4517-
pSMB->SearchFlags =
4518-
cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME);
4516+
pSMB->SearchFlags = cpu_to_le16(search_flags);
45194517

45204518
name_len = psrch_inf->resume_name_len;
45214519
params += name_len;

fs/cifs/readdir.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb,
219219

220220
static int initiate_cifs_search(const int xid, struct file *file)
221221
{
222+
__u16 search_flags;
222223
int rc = 0;
223224
char *full_path = NULL;
224225
struct cifsFileInfo *cifsFile;
@@ -270,8 +271,12 @@ static int initiate_cifs_search(const int xid, struct file *file)
270271
cifsFile->srch_inf.info_level = SMB_FIND_FILE_DIRECTORY_INFO;
271272
}
272273

274+
search_flags = CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME;
275+
if (backup_cred(cifs_sb))
276+
search_flags |= CIFS_SEARCH_BACKUP_SEARCH;
277+
273278
rc = CIFSFindFirst(xid, pTcon, full_path, cifs_sb->local_nls,
274-
&cifsFile->netfid, &cifsFile->srch_inf,
279+
&cifsFile->netfid, search_flags, &cifsFile->srch_inf,
275280
cifs_sb->mnt_cifs_flags &
276281
CIFS_MOUNT_MAP_SPECIAL_CHR, CIFS_DIR_SEP(cifs_sb));
277282
if (rc == 0)
@@ -502,11 +507,13 @@ static int cifs_save_resume_key(const char *current_entry,
502507
static int find_cifs_entry(const int xid, struct cifs_tcon *pTcon,
503508
struct file *file, char **ppCurrentEntry, int *num_to_ret)
504509
{
510+
__u16 search_flags;
505511
int rc = 0;
506512
int pos_in_buf = 0;
507513
loff_t first_entry_in_buffer;
508514
loff_t index_to_find = file->f_pos;
509515
struct cifsFileInfo *cifsFile = file->private_data;
516+
struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
510517
/* check if index in the buffer */
511518

512519
if ((cifsFile == NULL) || (ppCurrentEntry == NULL) ||
@@ -560,10 +567,14 @@ static int find_cifs_entry(const int xid, struct cifs_tcon *pTcon,
560567
cifsFile);
561568
}
562569

570+
search_flags = CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME;
571+
if (backup_cred(cifs_sb))
572+
search_flags |= CIFS_SEARCH_BACKUP_SEARCH;
573+
563574
while ((index_to_find >= cifsFile->srch_inf.index_of_last_entry) &&
564575
(rc == 0) && !cifsFile->srch_inf.endOfSearch) {
565576
cFYI(1, "calling findnext2");
566-
rc = CIFSFindNext(xid, pTcon, cifsFile->netfid,
577+
rc = CIFSFindNext(xid, pTcon, cifsFile->netfid, search_flags,
567578
&cifsFile->srch_inf);
568579
/* FindFirst/Next set last_entry to NULL on malformed reply */
569580
if (cifsFile->srch_inf.last_entry)

0 commit comments

Comments
 (0)