Skip to content

Commit

Permalink
CIFS: Move readdir code to ops struct
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Shilovsky <[email protected]>
Signed-off-by: Steve French <[email protected]>
  • Loading branch information
piastry authored and smfrench committed Sep 25, 2012
1 parent 1feeaac commit 92fc65a
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 103 deletions.
15 changes: 15 additions & 0 deletions fs/cifs/cifsglob.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ struct cifs_fid;
struct cifs_readdata;
struct cifs_writedata;
struct cifs_io_parms;
struct cifs_search_info;

struct smb_version_operations {
int (*send_cancel)(struct TCP_Server_Info *, void *,
Expand Down Expand Up @@ -313,6 +314,20 @@ struct smb_version_operations {
int (*sync_write)(const unsigned int, struct cifsFileInfo *,
struct cifs_io_parms *, unsigned int *, struct kvec *,
unsigned long);
/* open dir, start readdir */
int (*query_dir_first)(const unsigned int, struct cifs_tcon *,
const char *, struct cifs_sb_info *,
struct cifs_fid *, __u16,
struct cifs_search_info *);
/* continue readdir */
int (*query_dir_next)(const unsigned int, struct cifs_tcon *,
struct cifs_fid *,
__u16, struct cifs_search_info *srch_inf);
/* close dir */
int (*close_dir)(const unsigned int, struct cifs_tcon *,
struct cifs_fid *);
/* calculate a size of SMB message */
unsigned int (*calc_smb_size)(void *);
};

struct smb_version_values {
Expand Down
2 changes: 1 addition & 1 deletion fs/cifs/cifsproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
unsigned int bytes_written);
extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool);
extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool);
extern unsigned int smbCalcSize(struct smb_hdr *ptr);
extern unsigned int smbCalcSize(void *buf);
extern int decode_negTokenInit(unsigned char *security_blob, int length,
struct TCP_Server_Info *server);
extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
Expand Down
60 changes: 34 additions & 26 deletions fs/cifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,39 +618,47 @@ int cifs_closedir(struct inode *inode, struct file *file)
int rc = 0;
unsigned int xid;
struct cifsFileInfo *cfile = file->private_data;
char *tmp;
struct cifs_tcon *tcon;
struct TCP_Server_Info *server;
char *buf;

cFYI(1, "Closedir inode = 0x%p", inode);

if (cfile == NULL)
return rc;

xid = get_xid();
tcon = tlink_tcon(cfile->tlink);
server = tcon->ses->server;

if (cfile) {
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
cFYI(1, "Freeing private data in close dir");
spin_lock(&cifs_file_list_lock);
if (!cfile->srch_inf.endOfSearch && !cfile->invalidHandle) {
cfile->invalidHandle = true;
spin_unlock(&cifs_file_list_lock);
if (server->ops->close_dir)
rc = server->ops->close_dir(xid, tcon, &cfile->fid);
else
rc = -ENOSYS;
cFYI(1, "Closing uncompleted readdir with rc %d", rc);
/* not much we can do if it fails anyway, ignore rc */
rc = 0;
} else
spin_unlock(&cifs_file_list_lock);

cFYI(1, "Freeing private data in close dir");
spin_lock(&cifs_file_list_lock);
if (!cfile->srch_inf.endOfSearch && !cfile->invalidHandle) {
cfile->invalidHandle = true;
spin_unlock(&cifs_file_list_lock);
rc = CIFSFindClose(xid, tcon, cfile->fid.netfid);
cFYI(1, "Closing uncompleted readdir with rc %d", rc);
/* not much we can do if it fails anyway, ignore rc */
rc = 0;
} else
spin_unlock(&cifs_file_list_lock);
tmp = cfile->srch_inf.ntwrk_buf_start;
if (tmp) {
cFYI(1, "closedir free smb buf in srch struct");
cfile->srch_inf.ntwrk_buf_start = NULL;
if (cfile->srch_inf.smallBuf)
cifs_small_buf_release(tmp);
else
cifs_buf_release(tmp);
}
cifs_put_tlink(cfile->tlink);
kfree(file->private_data);
file->private_data = NULL;
buf = cfile->srch_inf.ntwrk_buf_start;
if (buf) {
cFYI(1, "closedir free smb buf in srch struct");
cfile->srch_inf.ntwrk_buf_start = NULL;
if (cfile->srch_inf.smallBuf)
cifs_small_buf_release(buf);
else
cifs_buf_release(buf);
}

cifs_put_tlink(cfile->tlink);
kfree(file->private_data);
file->private_data = NULL;
/* BB can we lock the filestruct while this is going on? */
free_xid(xid);
return rc;
Expand Down
3 changes: 2 additions & 1 deletion fs/cifs/netmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,9 @@ map_smb_to_linux_error(char *buf, bool logErr)
* portion, the number of word parameters and the data portion of the message
*/
unsigned int
smbCalcSize(struct smb_hdr *ptr)
smbCalcSize(void *buf)
{
struct smb_hdr *ptr = (struct smb_hdr *)buf;
return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
2 /* size of the bcc field */ + get_bcc(ptr));
}
Expand Down
Loading

0 comments on commit 92fc65a

Please sign in to comment.