Commit fb1214e4 authored by Pavel Shilovsky's avatar Pavel Shilovsky Committed by Steve French

CIFS: Move open code to ops struct

Acked-by: default avatarJeff Layton <jlayton@redhat.com>
Signed-off-by: default avatarPavel Shilovsky <pshilovsky@samba.org>
Signed-off-by: default avatarSteve French <smfrench@gmail.com>
parent 4b4de76e
...@@ -171,6 +171,7 @@ struct cifs_tcon; ...@@ -171,6 +171,7 @@ struct cifs_tcon;
struct dfs_info3_param; struct dfs_info3_param;
struct cifs_fattr; struct cifs_fattr;
struct smb_vol; struct smb_vol;
struct cifs_fid;
struct smb_version_operations { struct smb_version_operations {
int (*send_cancel)(struct TCP_Server_Info *, void *, int (*send_cancel)(struct TCP_Server_Info *, void *,
...@@ -262,6 +263,12 @@ struct smb_version_operations { ...@@ -262,6 +263,12 @@ struct smb_version_operations {
/* open, rename and delete file */ /* open, rename and delete file */
int (*rename_pending_delete)(const char *, struct dentry *, int (*rename_pending_delete)(const char *, struct dentry *,
const unsigned int); const unsigned int);
/* open a file for non-posix mounts */
int (*open)(const unsigned int, struct cifs_tcon *, const char *, int,
int, int, struct cifs_fid *, __u32 *, FILE_ALL_INFO *,
struct cifs_sb_info *);
/* set fid protocol-specific info */
void (*set_fid)(struct cifsFileInfo *, struct cifs_fid *, __u32);
}; };
struct smb_version_values { struct smb_version_values {
......
...@@ -121,9 +121,10 @@ extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, ...@@ -121,9 +121,10 @@ extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time,
int offset); int offset);
extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock); extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock);
extern struct cifsFileInfo *cifs_new_fileinfo(__u16 fileHandle, extern struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid,
struct file *file, struct tcon_link *tlink, struct file *file,
__u32 oplock); struct tcon_link *tlink,
__u32 oplock);
extern int cifs_posix_open(char *full_path, struct inode **inode, extern int cifs_posix_open(char *full_path, struct inode **inode,
struct super_block *sb, int mode, struct super_block *sb, int mode,
unsigned int f_flags, __u32 *oplock, __u16 *netfid, unsigned int f_flags, __u32 *oplock, __u16 *netfid,
......
...@@ -377,11 +377,12 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry, ...@@ -377,11 +377,12 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
unsigned int xid; unsigned int xid;
struct tcon_link *tlink; struct tcon_link *tlink;
struct cifs_tcon *tcon; struct cifs_tcon *tcon;
__u16 fileHandle; struct cifs_fid fid;
__u32 oplock; __u32 oplock;
struct cifsFileInfo *pfile_info; struct cifsFileInfo *file_info;
/* Posix open is only called (at lookup time) for file create now. For /*
* Posix open is only called (at lookup time) for file create now. For
* opens (rather than creates), because we do not know if it is a file * opens (rather than creates), because we do not know if it is a file
* or directory yet, and current Samba no longer allows us to do posix * or directory yet, and current Samba no longer allows us to do posix
* open on dirs, we could end up wasting an open call on what turns out * open on dirs, we could end up wasting an open call on what turns out
...@@ -415,20 +416,20 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry, ...@@ -415,20 +416,20 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
tcon = tlink_tcon(tlink); tcon = tlink_tcon(tlink);
rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode, rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
&oplock, &fileHandle, opened); &oplock, &fid.netfid, opened);
if (rc) if (rc)
goto out; goto out;
rc = finish_open(file, direntry, generic_file_open, opened); rc = finish_open(file, direntry, generic_file_open, opened);
if (rc) { if (rc) {
CIFSSMBClose(xid, tcon, fileHandle); CIFSSMBClose(xid, tcon, fid.netfid);
goto out; goto out;
} }
pfile_info = cifs_new_fileinfo(fileHandle, file, tlink, oplock); file_info = cifs_new_fileinfo(&fid, file, tlink, oplock);
if (pfile_info == NULL) { if (file_info == NULL) {
CIFSSMBClose(xid, tcon, fileHandle); CIFSSMBClose(xid, tcon, fid.netfid);
rc = -ENOMEM; rc = -ENOMEM;
} }
......
...@@ -169,16 +169,19 @@ int cifs_posix_open(char *full_path, struct inode **pinode, ...@@ -169,16 +169,19 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
static int static int
cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
struct cifs_tcon *tcon, unsigned int f_flags, __u32 *poplock, struct cifs_tcon *tcon, unsigned int f_flags, __u32 *oplock,
__u16 *pnetfid, unsigned int xid) struct cifs_fid *fid, unsigned int xid)
{ {
int rc; int rc;
int desiredAccess; int desired_access;
int disposition; int disposition;
int create_options = CREATE_NOT_DIR; int create_options = CREATE_NOT_DIR;
FILE_ALL_INFO *buf; FILE_ALL_INFO *buf;
desiredAccess = cifs_convert_flags(f_flags); if (!tcon->ses->server->ops->open)
return -ENOSYS;
desired_access = cifs_convert_flags(f_flags);
/********************************************************************* /*********************************************************************
* open flag mapping table: * open flag mapping table:
...@@ -215,16 +218,9 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, ...@@ -215,16 +218,9 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
if (backup_cred(cifs_sb)) if (backup_cred(cifs_sb))
create_options |= CREATE_OPEN_BACKUP_INTENT; create_options |= CREATE_OPEN_BACKUP_INTENT;
if (tcon->ses->capabilities & CAP_NT_SMBS) rc = tcon->ses->server->ops->open(xid, tcon, full_path, disposition,
rc = CIFSSMBOpen(xid, tcon, full_path, disposition, desired_access, create_options, fid,
desiredAccess, create_options, pnetfid, poplock, buf, oplock, buf, cifs_sb);
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR);
else
rc = SMBLegacyOpen(xid, tcon, full_path, disposition,
desiredAccess, CREATE_NOT_DIR, pnetfid, poplock, buf,
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR);
if (rc) if (rc)
goto out; goto out;
...@@ -234,7 +230,7 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, ...@@ -234,7 +230,7 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
xid); xid);
else else
rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb, rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb,
xid, pnetfid); xid, &fid->netfid);
out: out:
kfree(buf); kfree(buf);
...@@ -242,7 +238,7 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, ...@@ -242,7 +238,7 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
} }
struct cifsFileInfo * struct cifsFileInfo *
cifs_new_fileinfo(__u16 fileHandle, struct file *file, cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
struct tcon_link *tlink, __u32 oplock) struct tcon_link *tlink, __u32 oplock)
{ {
struct dentry *dentry = file->f_path.dentry; struct dentry *dentry = file->f_path.dentry;
...@@ -255,7 +251,6 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file, ...@@ -255,7 +251,6 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file,
return cfile; return cfile;
cfile->count = 1; cfile->count = 1;
cfile->fid.netfid = fileHandle;
cfile->pid = current->tgid; cfile->pid = current->tgid;
cfile->uid = current_fsuid(); cfile->uid = current_fsuid();
cfile->dentry = dget(dentry); cfile->dentry = dget(dentry);
...@@ -265,6 +260,7 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file, ...@@ -265,6 +260,7 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file,
mutex_init(&cfile->fh_mutex); mutex_init(&cfile->fh_mutex);
INIT_WORK(&cfile->oplock_break, cifs_oplock_break); INIT_WORK(&cfile->oplock_break, cifs_oplock_break);
INIT_LIST_HEAD(&cfile->llist); INIT_LIST_HEAD(&cfile->llist);
tlink_tcon(tlink)->ses->server->ops->set_fid(cfile, fid, oplock);
spin_lock(&cifs_file_list_lock); spin_lock(&cifs_file_list_lock);
list_add(&cfile->tlist, &(tlink_tcon(tlink)->openFileList)); list_add(&cfile->tlist, &(tlink_tcon(tlink)->openFileList));
...@@ -275,9 +271,6 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file, ...@@ -275,9 +271,6 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file,
list_add_tail(&cfile->flist, &cinode->openFileList); list_add_tail(&cfile->flist, &cinode->openFileList);
spin_unlock(&cifs_file_list_lock); spin_unlock(&cifs_file_list_lock);
cifs_set_oplock_level(cinode, oplock);
cinode->can_cache_brlcks = cinode->clientCanCacheAll;
file->private_data = cfile; file->private_data = cfile;
return cfile; return cfile;
} }
...@@ -364,10 +357,10 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -364,10 +357,10 @@ int cifs_open(struct inode *inode, struct file *file)
struct cifs_sb_info *cifs_sb; struct cifs_sb_info *cifs_sb;
struct cifs_tcon *tcon; struct cifs_tcon *tcon;
struct tcon_link *tlink; struct tcon_link *tlink;
struct cifsFileInfo *pCifsFile = NULL; struct cifsFileInfo *cfile = NULL;
char *full_path = NULL; char *full_path = NULL;
bool posix_open_ok = false; bool posix_open_ok = false;
__u16 netfid; struct cifs_fid fid;
xid = get_xid(); xid = get_xid();
...@@ -399,7 +392,7 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -399,7 +392,7 @@ int cifs_open(struct inode *inode, struct file *file)
/* can not refresh inode info since size could be stale */ /* can not refresh inode info since size could be stale */
rc = cifs_posix_open(full_path, &inode, inode->i_sb, rc = cifs_posix_open(full_path, &inode, inode->i_sb,
cifs_sb->mnt_file_mode /* ignored */, cifs_sb->mnt_file_mode /* ignored */,
file->f_flags, &oplock, &netfid, xid); file->f_flags, &oplock, &fid.netfid, xid);
if (rc == 0) { if (rc == 0) {
cFYI(1, "posix open succeeded"); cFYI(1, "posix open succeeded");
posix_open_ok = true; posix_open_ok = true;
...@@ -415,20 +408,22 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -415,20 +408,22 @@ int cifs_open(struct inode *inode, struct file *file)
} else if ((rc != -EIO) && (rc != -EREMOTE) && } else if ((rc != -EIO) && (rc != -EREMOTE) &&
(rc != -EOPNOTSUPP)) /* path not found or net err */ (rc != -EOPNOTSUPP)) /* path not found or net err */
goto out; goto out;
/* else fallthrough to retry open the old way on network i/o /*
or DFS errors */ * Else fallthrough to retry open the old way on network i/o
* or DFS errors.
*/
} }
if (!posix_open_ok) { if (!posix_open_ok) {
rc = cifs_nt_open(full_path, inode, cifs_sb, tcon, rc = cifs_nt_open(full_path, inode, cifs_sb, tcon,
file->f_flags, &oplock, &netfid, xid); file->f_flags, &oplock, &fid, xid);
if (rc) if (rc)
goto out; goto out;
} }
pCifsFile = cifs_new_fileinfo(netfid, file, tlink, oplock); cfile = cifs_new_fileinfo(&fid, file, tlink, oplock);
if (pCifsFile == NULL) { if (cfile == NULL) {
CIFSSMBClose(xid, tcon, netfid); CIFSSMBClose(xid, tcon, fid.netfid);
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
} }
...@@ -436,8 +431,10 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -436,8 +431,10 @@ int cifs_open(struct inode *inode, struct file *file)
cifs_fscache_set_inode_cookie(inode, file); cifs_fscache_set_inode_cookie(inode, file);
if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) { if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) {
/* time to set mode which we can not set earlier due to /*
problems creating new read-only files */ * Time to set mode which we can not set earlier due to
* problems creating new read-only files.
*/
struct cifs_unix_set_info_args args = { struct cifs_unix_set_info_args args = {
.mode = inode->i_mode, .mode = inode->i_mode,
.uid = NO_CHANGE_64, .uid = NO_CHANGE_64,
...@@ -447,8 +444,8 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -447,8 +444,8 @@ int cifs_open(struct inode *inode, struct file *file)
.mtime = NO_CHANGE_64, .mtime = NO_CHANGE_64,
.device = 0, .device = 0,
}; };
CIFSSMBUnixSetFileInfo(xid, tcon, &args, netfid, CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid.netfid,
pCifsFile->pid); cfile->pid);
} }
out: out:
......
...@@ -607,6 +607,33 @@ cifs_mkdir_setinfo(struct inode *inode, const char *full_path, ...@@ -607,6 +607,33 @@ cifs_mkdir_setinfo(struct inode *inode, const char *full_path,
cifsInode->cifsAttrs = dosattrs; cifsInode->cifsAttrs = dosattrs;
} }
static int
cifs_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path,
int disposition, int desired_access, int create_options,
struct cifs_fid *fid, __u32 *oplock, FILE_ALL_INFO *buf,
struct cifs_sb_info *cifs_sb)
{
if (!(tcon->ses->capabilities & CAP_NT_SMBS))
return SMBLegacyOpen(xid, tcon, path, disposition,
desired_access, CREATE_NOT_DIR,
&fid->netfid, oplock, buf,
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR);
return CIFSSMBOpen(xid, tcon, path, disposition, desired_access,
create_options, &fid->netfid, oplock, buf,
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
CIFS_MOUNT_MAP_SPECIAL_CHR);
}
static void
cifs_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
{
struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
cfile->fid.netfid = fid->netfid;
cifs_set_oplock_level(cinode, oplock);
cinode->can_cache_brlcks = cinode->clientCanCacheAll;
}
struct smb_version_operations smb1_operations = { struct smb_version_operations smb1_operations = {
.send_cancel = send_nt_cancel, .send_cancel = send_nt_cancel,
.compare_fids = cifs_compare_fids, .compare_fids = cifs_compare_fids,
...@@ -646,6 +673,8 @@ struct smb_version_operations smb1_operations = { ...@@ -646,6 +673,8 @@ struct smb_version_operations smb1_operations = {
.rmdir = CIFSSMBRmDir, .rmdir = CIFSSMBRmDir,
.unlink = CIFSSMBDelFile, .unlink = CIFSSMBDelFile,
.rename_pending_delete = cifs_rename_pending_delete, .rename_pending_delete = cifs_rename_pending_delete,
.open = cifs_open_file,
.set_fid = cifs_set_fid,
}; };
struct smb_version_values smb1_values = { struct smb_version_values smb1_values = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment