mirror of https://gitee.com/openkylin/linux.git
CIFS: Move unlink code to ops struct
Reviewed-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org> Signed-off-by: Steve French <smfrench@gmail.com>
This commit is contained in:
parent
56d27adcb5
commit
ed6875e0d6
|
@ -256,6 +256,12 @@ struct smb_version_operations {
|
||||||
/* remove directory */
|
/* remove directory */
|
||||||
int (*rmdir)(const unsigned int, struct cifs_tcon *, const char *,
|
int (*rmdir)(const unsigned int, struct cifs_tcon *, const char *,
|
||||||
struct cifs_sb_info *);
|
struct cifs_sb_info *);
|
||||||
|
/* unlink file */
|
||||||
|
int (*unlink)(const unsigned int, struct cifs_tcon *, const char *,
|
||||||
|
struct cifs_sb_info *);
|
||||||
|
/* open, rename and delete file */
|
||||||
|
int (*rename_pending_delete)(const char *, struct dentry *,
|
||||||
|
const unsigned int);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct smb_version_values {
|
struct smb_version_values {
|
||||||
|
|
|
@ -144,6 +144,11 @@ extern int cifs_get_file_info_unix(struct file *filp);
|
||||||
extern int cifs_get_inode_info_unix(struct inode **pinode,
|
extern int cifs_get_inode_info_unix(struct inode **pinode,
|
||||||
const unsigned char *search_path,
|
const unsigned char *search_path,
|
||||||
struct super_block *sb, unsigned int xid);
|
struct super_block *sb, unsigned int xid);
|
||||||
|
extern int cifs_set_file_info(struct inode *inode, struct iattr *attrs,
|
||||||
|
unsigned int xid, char *full_path, __u32 dosattr);
|
||||||
|
extern int cifs_rename_pending_delete(const char *full_path,
|
||||||
|
struct dentry *dentry,
|
||||||
|
const unsigned int xid);
|
||||||
extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb,
|
extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb,
|
||||||
struct cifs_fattr *fattr, struct inode *inode,
|
struct cifs_fattr *fattr, struct inode *inode,
|
||||||
const char *path, const __u16 *pfid);
|
const char *path, const __u16 *pfid);
|
||||||
|
@ -303,9 +308,7 @@ extern int CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon,
|
||||||
const struct nls_table *nls_codepage,
|
const struct nls_table *nls_codepage,
|
||||||
int remap_special_chars);
|
int remap_special_chars);
|
||||||
extern int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon,
|
extern int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon,
|
||||||
const char *name,
|
const char *name, struct cifs_sb_info *cifs_sb);
|
||||||
const struct nls_table *nls_codepage,
|
|
||||||
int remap_special_chars);
|
|
||||||
extern int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon,
|
extern int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon,
|
||||||
const char *fromName, const char *toName,
|
const char *fromName, const char *toName,
|
||||||
const struct nls_table *nls_codepage,
|
const struct nls_table *nls_codepage,
|
||||||
|
|
|
@ -902,15 +902,15 @@ CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon,
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon,
|
CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
|
||||||
const char *fileName, const struct nls_table *nls_codepage,
|
struct cifs_sb_info *cifs_sb)
|
||||||
int remap)
|
|
||||||
{
|
{
|
||||||
DELETE_FILE_REQ *pSMB = NULL;
|
DELETE_FILE_REQ *pSMB = NULL;
|
||||||
DELETE_FILE_RSP *pSMBr = NULL;
|
DELETE_FILE_RSP *pSMBr = NULL;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
int bytes_returned;
|
int bytes_returned;
|
||||||
int name_len;
|
int name_len;
|
||||||
|
int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
|
||||||
|
|
||||||
DelFileRetry:
|
DelFileRetry:
|
||||||
rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB,
|
rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB,
|
||||||
|
@ -919,15 +919,15 @@ CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon,
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
|
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
|
||||||
name_len =
|
name_len = cifsConvertToUTF16((__le16 *) pSMB->fileName, name,
|
||||||
cifsConvertToUTF16((__le16 *) pSMB->fileName, fileName,
|
PATH_MAX, cifs_sb->local_nls,
|
||||||
PATH_MAX, nls_codepage, remap);
|
remap);
|
||||||
name_len++; /* trailing null */
|
name_len++; /* trailing null */
|
||||||
name_len *= 2;
|
name_len *= 2;
|
||||||
} else { /* BB improve check for buffer overruns BB */
|
} else { /* BB improve check for buffer overruns BB */
|
||||||
name_len = strnlen(fileName, PATH_MAX);
|
name_len = strnlen(name, PATH_MAX);
|
||||||
name_len++; /* trailing null */
|
name_len++; /* trailing null */
|
||||||
strncpy(pSMB->fileName, fileName, name_len);
|
strncpy(pSMB->fileName, name, name_len);
|
||||||
}
|
}
|
||||||
pSMB->SearchAttributes =
|
pSMB->SearchAttributes =
|
||||||
cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM);
|
cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM);
|
||||||
|
|
|
@ -876,9 +876,9 @@ struct inode *cifs_root_iget(struct super_block *sb)
|
||||||
return inode;
|
return inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
int
|
||||||
cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid,
|
cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid,
|
||||||
char *full_path, __u32 dosattr)
|
char *full_path, __u32 dosattr)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
int oplock = 0;
|
int oplock = 0;
|
||||||
|
@ -993,13 +993,13 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* open the given file (if it isn't already), set the DELETE_ON_CLOSE bit
|
* Open the given file (if it isn't already), set the DELETE_ON_CLOSE bit
|
||||||
* and rename it to a random name that hopefully won't conflict with
|
* and rename it to a random name that hopefully won't conflict with
|
||||||
* anything else.
|
* anything else.
|
||||||
*/
|
*/
|
||||||
static int
|
int
|
||||||
cifs_rename_pending_delete(char *full_path, struct dentry *dentry,
|
cifs_rename_pending_delete(const char *full_path, struct dentry *dentry,
|
||||||
unsigned int xid)
|
const unsigned int xid)
|
||||||
{
|
{
|
||||||
int oplock = 0;
|
int oplock = 0;
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -1136,6 +1136,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
|
||||||
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
|
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
|
||||||
struct tcon_link *tlink;
|
struct tcon_link *tlink;
|
||||||
struct cifs_tcon *tcon;
|
struct cifs_tcon *tcon;
|
||||||
|
struct TCP_Server_Info *server;
|
||||||
struct iattr *attrs = NULL;
|
struct iattr *attrs = NULL;
|
||||||
__u32 dosattr = 0, origattr = 0;
|
__u32 dosattr = 0, origattr = 0;
|
||||||
|
|
||||||
|
@ -1145,6 +1146,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
|
||||||
if (IS_ERR(tlink))
|
if (IS_ERR(tlink))
|
||||||
return PTR_ERR(tlink);
|
return PTR_ERR(tlink);
|
||||||
tcon = tlink_tcon(tlink);
|
tcon = tlink_tcon(tlink);
|
||||||
|
server = tcon->ses->server;
|
||||||
|
|
||||||
xid = get_xid();
|
xid = get_xid();
|
||||||
|
|
||||||
|
@ -1167,8 +1169,12 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
|
||||||
}
|
}
|
||||||
|
|
||||||
retry_std_delete:
|
retry_std_delete:
|
||||||
rc = CIFSSMBDelFile(xid, tcon, full_path, cifs_sb->local_nls,
|
if (!server->ops->unlink) {
|
||||||
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
|
rc = -ENOSYS;
|
||||||
|
goto psx_del_no_retry;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = server->ops->unlink(xid, tcon, full_path, cifs_sb);
|
||||||
|
|
||||||
psx_del_no_retry:
|
psx_del_no_retry:
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
|
@ -1177,9 +1183,14 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
|
||||||
} else if (rc == -ENOENT) {
|
} else if (rc == -ENOENT) {
|
||||||
d_drop(dentry);
|
d_drop(dentry);
|
||||||
} else if (rc == -ETXTBSY) {
|
} else if (rc == -ETXTBSY) {
|
||||||
rc = cifs_rename_pending_delete(full_path, dentry, xid);
|
if (server->ops->rename_pending_delete) {
|
||||||
if (rc == 0)
|
rc = server->ops->rename_pending_delete(full_path,
|
||||||
cifs_drop_nlink(inode);
|
dentry, xid);
|
||||||
|
if (rc == 0)
|
||||||
|
cifs_drop_nlink(inode);
|
||||||
|
}
|
||||||
|
if (rc == -ETXTBSY)
|
||||||
|
rc = -EBUSY;
|
||||||
} else if ((rc == -EACCES) && (dosattr == 0) && inode) {
|
} else if ((rc == -EACCES) && (dosattr == 0) && inode) {
|
||||||
attrs = kzalloc(sizeof(*attrs), GFP_KERNEL);
|
attrs = kzalloc(sizeof(*attrs), GFP_KERNEL);
|
||||||
if (attrs == NULL) {
|
if (attrs == NULL) {
|
||||||
|
|
|
@ -644,6 +644,8 @@ struct smb_version_operations smb1_operations = {
|
||||||
.mkdir = CIFSSMBMkDir,
|
.mkdir = CIFSSMBMkDir,
|
||||||
.mkdir_setinfo = cifs_mkdir_setinfo,
|
.mkdir_setinfo = cifs_mkdir_setinfo,
|
||||||
.rmdir = CIFSSMBRmDir,
|
.rmdir = CIFSSMBRmDir,
|
||||||
|
.unlink = CIFSSMBDelFile,
|
||||||
|
.rename_pending_delete = cifs_rename_pending_delete,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct smb_version_values smb1_values = {
|
struct smb_version_values smb1_values = {
|
||||||
|
|
Loading…
Reference in New Issue