Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
etercifs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
etercifs
Commits
f87f60b3
Commit
f87f60b3
authored
Apr 05, 2011
by
Pavel Shilovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add strict cache mode for 2.6.35
parent
edc2bedb
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
512 additions
and
124 deletions
+512
-124
README
sources/2.6.35/README
+5
-0
cifs_fs_sb.h
sources/2.6.35/cifs_fs_sb.h
+1
-0
cifsfs.c
sources/2.6.35/cifsfs.c
+48
-4
cifsfs.h
sources/2.6.35/cifsfs.h
+13
-4
cifsproto.h
sources/2.6.35/cifsproto.h
+3
-0
connect.c
sources/2.6.35/connect.c
+6
-1
dir.c
sources/2.6.35/dir.c
+3
-8
file.c
sources/2.6.35/file.c
+394
-98
inode.c
sources/2.6.35/inode.c
+15
-4
misc.c
sources/2.6.35/misc.c
+24
-5
No files found.
sources/2.6.35/README
View file @
f87f60b3
...
...
@@ -433,6 +433,11 @@ A partial list of the supported mount options follows:
if oplock (caching token) is granted and held. Note that
direct allows write operations larger than page size
to be sent to the server.
strictcache Use for switching on strict cache mode. In this mode the
client reads from the cache all the time it has Oplock Level II,
otherwise - reads from the server. All written data are stored
in the cache, but if the client doesn't have Exclusive Oplock,
it writes the data to the server.
acl Allow setfacl and getfacl to manage posix ACLs if server
supports them. (default)
noacl Do not allow setfacl and getfacl calls on this mount
...
...
sources/2.6.35/cifs_fs_sb.h
View file @
f87f60b3
...
...
@@ -36,6 +36,7 @@
#define CIFS_MOUNT_NOPOSIXBRL 0x2000
/* mandatory not posix byte range lock */
#define CIFS_MOUNT_NOSSYNC 0x4000
/* don't do slow SMBflush on every sync*/
#define CIFS_MOUNT_WINE_MODE 0x8000
/* use pid forwarding for wine apps */
#define CIFS_MOUNT_STRICT_IO 0x10000
/* strict cache mode */
struct
cifs_sb_info
{
struct
cifsTconInfo
*
tcon
;
/* primary mount */
...
...
sources/2.6.35/cifsfs.c
View file @
f87f60b3
...
...
@@ -308,8 +308,7 @@ cifs_alloc_inode(struct super_block *sb)
/* Until the file is open and we have gotten oplock
info back from the server, can not assume caching of
file data or metadata */
cifs_inode
->
clientCanCacheRead
=
false
;
cifs_inode
->
clientCanCacheAll
=
false
;
cifs_set_oplock_level
(
cifs_inode
,
0
);
cifs_inode
->
delete_pending
=
false
;
cifs_inode
->
invalid_mapping
=
false
;
cifs_inode
->
vfs_inode
.
i_blkbits
=
14
;
/* 2**14 = CIFS_MAX_MSGSIZE */
...
...
@@ -538,10 +537,17 @@ static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
{
struct
inode
*
inode
=
iocb
->
ki_filp
->
f_path
.
dentry
->
d_inode
;
ssize_t
written
;
int
rc
;
written
=
generic_file_aio_write
(
iocb
,
iov
,
nr_segs
,
pos
);
if
(
!
CIFS_I
(
inode
)
->
clientCanCacheAll
)
filemap_fdatawrite
(
inode
->
i_mapping
);
if
(
CIFS_I
(
inode
)
->
clientCanCacheAll
)
return
written
;
rc
=
filemap_fdatawrite
(
inode
->
i_mapping
);
if
(
rc
)
cFYI
(
1
,
"cifs_file_aio_write: %d rc on %p inode"
,
rc
,
inode
);
return
written
;
}
...
...
@@ -670,6 +676,25 @@ const struct file_operations cifs_file_ops = {
.
setlease
=
cifs_setlease
,
};
const
struct
file_operations
cifs_file_strict_ops
=
{
.
read
=
do_sync_read
,
.
write
=
do_sync_write
,
.
aio_read
=
cifs_strict_readv
,
.
aio_write
=
cifs_strict_writev
,
.
open
=
cifs_open
,
.
release
=
cifs_close
,
.
lock
=
cifs_lock
,
.
fsync
=
cifs_strict_fsync
,
.
flush
=
cifs_flush
,
.
mmap
=
cifs_file_strict_mmap
,
.
splice_read
=
generic_file_splice_read
,
.
llseek
=
cifs_llseek
,
#ifdef CONFIG_CIFS_POSIX
.
unlocked_ioctl
=
cifs_ioctl
,
#endif
/* CONFIG_CIFS_POSIX */
.
setlease
=
cifs_setlease
,
};
const
struct
file_operations
cifs_file_direct_ops
=
{
/* no aio, no readv -
BB reevaluate whether they can be done with directio, no cache */
...
...
@@ -688,6 +713,7 @@ const struct file_operations cifs_file_direct_ops = {
.
llseek
=
cifs_llseek
,
.
setlease
=
cifs_setlease
,
};
const
struct
file_operations
cifs_file_nobrl_ops
=
{
.
read
=
do_sync_read
,
.
write
=
do_sync_write
,
...
...
@@ -706,6 +732,24 @@ const struct file_operations cifs_file_nobrl_ops = {
.
setlease
=
cifs_setlease
,
};
const
struct
file_operations
cifs_file_strict_nobrl_ops
=
{
.
read
=
do_sync_read
,
.
write
=
do_sync_write
,
.
aio_read
=
cifs_strict_readv
,
.
aio_write
=
cifs_strict_writev
,
.
open
=
cifs_open
,
.
release
=
cifs_close
,
.
fsync
=
cifs_strict_fsync
,
.
flush
=
cifs_flush
,
.
mmap
=
cifs_file_strict_mmap
,
.
splice_read
=
generic_file_splice_read
,
.
llseek
=
cifs_llseek
,
#ifdef CONFIG_CIFS_POSIX
.
unlocked_ioctl
=
cifs_ioctl
,
#endif
/* CONFIG_CIFS_POSIX */
.
setlease
=
cifs_setlease
,
};
const
struct
file_operations
cifs_file_direct_nobrl_ops
=
{
/* no mmap, no aio, no readv -
BB reevaluate whether they can be done with directio, no cache */
...
...
sources/2.6.35/cifsfs.h
View file @
f87f60b3
...
...
@@ -63,6 +63,7 @@ extern int cifs_rename(struct inode *, struct dentry *, struct inode *,
struct
dentry
*
);
extern
int
cifs_revalidate_file
(
struct
file
*
filp
);
extern
int
cifs_revalidate_dentry
(
struct
dentry
*
);
extern
void
cifs_invalidate_mapping
(
struct
inode
*
inode
);
extern
int
cifs_getattr
(
struct
vfsmount
*
,
struct
dentry
*
,
struct
kstat
*
);
extern
int
cifs_setattr
(
struct
dentry
*
,
struct
iattr
*
);
...
...
@@ -74,19 +75,27 @@ extern const struct inode_operations cifs_dfs_referral_inode_operations;
/* Functions related to files and directories */
extern
const
struct
file_operations
cifs_file_ops
;
extern
const
struct
file_operations
cifs_file_direct_ops
;
/* if directio mnt */
extern
const
struct
file_operations
cifs_file_nobrl_ops
;
extern
const
struct
file_operations
cifs_file_direct_nobrl_ops
;
/* no brlocks */
extern
const
struct
file_operations
cifs_file_strict_ops
;
/* if strictio mnt */
extern
const
struct
file_operations
cifs_file_nobrl_ops
;
/* no brlocks */
extern
const
struct
file_operations
cifs_file_direct_nobrl_ops
;
extern
const
struct
file_operations
cifs_file_strict_nobrl_ops
;
extern
int
cifs_open
(
struct
inode
*
inode
,
struct
file
*
file
);
extern
int
cifs_close
(
struct
inode
*
inode
,
struct
file
*
file
);
extern
int
cifs_closedir
(
struct
inode
*
inode
,
struct
file
*
file
);
extern
ssize_t
cifs_user_read
(
struct
file
*
file
,
char
__user
*
read_data
,
size_t
read_size
,
loff_t
*
poffset
);
size_t
read_size
,
loff_t
*
poffset
);
extern
ssize_t
cifs_strict_readv
(
struct
kiocb
*
iocb
,
const
struct
iovec
*
iov
,
unsigned
long
nr_segs
,
loff_t
pos
);
extern
ssize_t
cifs_user_write
(
struct
file
*
file
,
const
char
__user
*
write_data
,
size_t
write_size
,
loff_t
*
poffset
);
size_t
write_size
,
loff_t
*
poffset
);
extern
ssize_t
cifs_strict_writev
(
struct
kiocb
*
iocb
,
const
struct
iovec
*
iov
,
unsigned
long
nr_segs
,
loff_t
pos
);
extern
int
cifs_lock
(
struct
file
*
,
int
,
struct
file_lock
*
);
extern
int
cifs_fsync
(
struct
file
*
,
int
);
extern
int
cifs_strict_fsync
(
struct
file
*
,
int
);
extern
int
cifs_flush
(
struct
file
*
,
fl_owner_t
id
);
extern
int
cifs_file_mmap
(
struct
file
*
,
struct
vm_area_struct
*
);
extern
int
cifs_file_strict_mmap
(
struct
file
*
,
struct
vm_area_struct
*
);
extern
const
struct
file_operations
cifs_dir_ops
;
extern
int
cifs_dir_open
(
struct
inode
*
inode
,
struct
file
*
file
);
extern
int
cifs_readdir
(
struct
file
*
file
,
void
*
direntry
,
filldir_t
filldir
);
...
...
sources/2.6.35/cifsproto.h
View file @
f87f60b3
...
...
@@ -82,6 +82,8 @@ extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *);
#ifdef CONFIG_CIFS_EXPERIMENTAL
extern
struct
cifsFileInfo
*
find_readable_file
(
struct
cifsInodeInfo
*
);
#endif
extern
void
cifs_update_eof
(
struct
cifsInodeInfo
*
cifsi
,
loff_t
offset
,
unsigned
int
bytes_written
);
extern
unsigned
int
smbCalcSize
(
struct
smb_hdr
*
ptr
);
extern
unsigned
int
smbCalcSize_LE
(
struct
smb_hdr
*
ptr
);
extern
int
decode_negTokenInit
(
unsigned
char
*
security_blob
,
int
length
,
...
...
@@ -101,6 +103,7 @@ extern struct timespec cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601);
extern
u64
cifs_UnixTimeToNT
(
struct
timespec
);
extern
struct
timespec
cnvrtDosUnixTm
(
__le16
le_date
,
__le16
le_time
,
int
offset
);
extern
void
cifs_set_oplock_level
(
struct
cifsInodeInfo
*
cinode
,
__u32
oplock
);
extern
struct
cifsFileInfo
*
cifs_new_fileinfo
(
struct
inode
*
newinode
,
__u16
fileHandle
,
struct
file
*
file
,
...
...
sources/2.6.35/connect.c
View file @
f87f60b3
...
...
@@ -83,6 +83,7 @@ struct smb_vol {
bool
no_xattr
:
1
;
/* set if xattr (EA) support should be disabled*/
bool
server_ino
:
1
;
/* use inode numbers from server ie UniqueId */
bool
direct_io
:
1
;
bool
strict_io
:
1
;
/* strict cache behavior */
bool
remap
:
1
;
/* set to remap seven reserved chars in filenames */
bool
posix_paths
:
1
;
/* unset to not ask for posix pathnames. */
bool
no_linux_ext
:
1
;
...
...
@@ -1307,7 +1308,7 @@ cifs_parse_mount_options(char *options, const char *devname,
}
else
if
(
strnicmp
(
data
,
"wine"
,
4
)
==
0
)
{
vol
->
wine_mode
=
1
;
vol
->
mand_lock
=
1
;
vol
->
dire
ct_io
=
1
;
vol
->
stri
ct_io
=
1
;
}
else
if
(
strnicmp
(
data
,
"cifsacl"
,
7
)
==
0
)
{
vol
->
cifs_acl
=
1
;
}
else
if
(
strnicmp
(
data
,
"nocifsacl"
,
9
)
==
0
)
{
...
...
@@ -1332,6 +1333,8 @@ cifs_parse_mount_options(char *options, const char *devname,
vol
->
direct_io
=
1
;
}
else
if
(
strnicmp
(
data
,
"forcedirectio"
,
13
)
==
0
)
{
vol
->
direct_io
=
1
;
}
else
if
(
strnicmp
(
data
,
"strictcache"
,
11
)
==
0
)
{
vol
->
strict_io
=
1
;
}
else
if
(
strnicmp
(
data
,
"noac"
,
4
)
==
0
)
{
printk
(
KERN_WARNING
"CIFS: Mount option noac not "
"supported. Instead set "
...
...
@@ -2427,6 +2430,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
cifs_sb
->
mnt_cifs_flags
|=
CIFS_MOUNT_OVERR_GID
;
if
(
pvolume_info
->
dynperm
)
cifs_sb
->
mnt_cifs_flags
|=
CIFS_MOUNT_DYNPERM
;
if
(
pvolume_info
->
strict_io
)
cifs_sb
->
mnt_cifs_flags
|=
CIFS_MOUNT_STRICT_IO
;
if
(
pvolume_info
->
direct_io
)
{
cFYI
(
1
,
"mounting share using direct i/o"
);
cifs_sb
->
mnt_cifs_flags
|=
CIFS_MOUNT_DIRECT_IO
;
...
...
sources/2.6.35/dir.c
View file @
f87f60b3
...
...
@@ -162,9 +162,11 @@ cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle,
atomic_set
(
&
pCifsFile
->
count
,
1
);
slow_work_init
(
&
pCifsFile
->
oplock_break
,
&
cifs_oplock_break_ops
);
pCifsInode
=
CIFS_I
(
newinode
);
if
(
pCifsInode
)
cifs_set_oplock_level
(
pCifsInode
,
oplock
);
write_lock
(
&
GlobalSMBSeslock
);
list_add
(
&
pCifsFile
->
tlist
,
&
cifs_sb
->
tcon
->
openFileList
);
pCifsInode
=
CIFS_I
(
newinode
);
if
(
pCifsInode
)
{
/* if readable file instance put first in list*/
if
(
oflags
&
FMODE_READ
)
...
...
@@ -172,13 +174,6 @@ cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle,
else
list_add_tail
(
&
pCifsFile
->
flist
,
&
pCifsInode
->
openFileList
);
if
((
oplock
&
0xF
)
==
OPLOCK_EXCLUSIVE
)
{
pCifsInode
->
clientCanCacheAll
=
true
;
pCifsInode
->
clientCanCacheRead
=
true
;
cFYI
(
1
,
"Exclusive Oplock inode %p"
,
newinode
);
}
else
if
((
oplock
&
0xF
)
==
OPLOCK_READ
)
pCifsInode
->
clientCanCacheRead
=
true
;
}
write_unlock
(
&
GlobalSMBSeslock
);
...
...
sources/2.6.35/file.c
View file @
f87f60b3
...
...
@@ -113,8 +113,7 @@ static inline int cifs_get_share_flags(unsigned int flags)
/* all arguments to this function must be checked for validity in caller */
static
inline
int
cifs_posix_open_inode_helper
(
struct
inode
*
inode
,
struct
file
*
file
,
struct
cifsInodeInfo
*
pCifsInode
,
__u32
oplock
,
u16
netfid
)
struct
cifsInodeInfo
*
pCifsInode
,
u16
netfid
)
{
write_lock
(
&
GlobalSMBSeslock
);
...
...
@@ -153,14 +152,6 @@ cifs_posix_open_inode_helper(struct inode *inode, struct file *file,
} */
psx_client_can_cache:
if
((
oplock
&
0xF
)
==
OPLOCK_EXCLUSIVE
)
{
pCifsInode
->
clientCanCacheAll
=
true
;
pCifsInode
->
clientCanCacheRead
=
true
;
cFYI
(
1
,
"Exclusive Oplock granted on inode %p"
,
file
->
f_path
.
dentry
->
d_inode
);
}
else
if
((
oplock
&
0xF
)
==
OPLOCK_READ
)
pCifsInode
->
clientCanCacheRead
=
true
;
/* will have to change the unlock if we reenable the
filemap_fdatawrite (which does not seem necessary */
write_unlock
(
&
GlobalSMBSeslock
);
...
...
@@ -169,7 +160,7 @@ psx_client_can_cache:
/* all arguments to this function must be checked for validity in caller */
static
inline
int
cifs_open_inode_helper
(
struct
inode
*
inode
,
struct
cifsTconInfo
*
pTcon
,
int
*
oplock
,
FILE_ALL_INFO
*
buf
,
struct
cifsTconInfo
*
pTcon
,
FILE_ALL_INFO
*
buf
,
char
*
full_path
,
int
xid
)
{
struct
cifsInodeInfo
*
pCifsInode
=
CIFS_I
(
inode
);
...
...
@@ -211,13 +202,6 @@ client_can_cache:
rc
=
cifs_get_inode_info
(
&
inode
,
full_path
,
buf
,
inode
->
i_sb
,
xid
,
NULL
);
if
((
*
oplock
&
0xF
)
==
OPLOCK_EXCLUSIVE
)
{
pCifsInode
->
clientCanCacheAll
=
true
;
pCifsInode
->
clientCanCacheRead
=
true
;
cFYI
(
1
,
"Exclusive Oplock granted on inode %p"
,
inode
);
}
else
if
((
*
oplock
&
0xF
)
==
OPLOCK_READ
)
pCifsInode
->
clientCanCacheRead
=
true
;
return
rc
;
}
...
...
@@ -276,7 +260,7 @@ int cifs_open(struct inode *inode, struct file *file)
on read only files needed here */
rc
=
cifs_posix_open_inode_helper
(
inode
,
file
,
pCifsInode
,
oplock
,
netfid
);
pCifsInode
,
netfid
);
if
(
rc
!=
0
)
{
CIFSSMBClose
(
xid
,
tcon
,
netfid
);
goto
out
;
...
...
@@ -370,7 +354,7 @@ int cifs_open(struct inode *inode, struct file *file)
goto
out
;
}
rc
=
cifs_open_inode_helper
(
inode
,
tcon
,
&
oplock
,
buf
,
full_path
,
xid
);
rc
=
cifs_open_inode_helper
(
inode
,
tcon
,
buf
,
full_path
,
xid
);
if
(
rc
!=
0
)
goto
out
;
...
...
@@ -535,8 +519,7 @@ reopen_success:
CIFS_I
(
inode
)
->
write_behind_rc
=
rc
;
/* temporarily disable caching while we
go to server to get inode info */
pCifsInode
->
clientCanCacheAll
=
false
;
pCifsInode
->
clientCanCacheRead
=
false
;
cifs_set_oplock_level
(
pCifsInode
,
0
);
if
(
tcon
->
unix_ext
)
rc
=
cifs_get_inode_info_unix
(
&
inode
,
full_path
,
inode
->
i_sb
,
xid
);
...
...
@@ -550,18 +533,7 @@ reopen_success:
invalidate the current end of file on the server
we can not go to the server to get the new inod
info */
if
((
oplock
&
0xF
)
==
OPLOCK_EXCLUSIVE
)
{
pCifsInode
->
clientCanCacheAll
=
true
;
pCifsInode
->
clientCanCacheRead
=
true
;
cFYI
(
1
,
"Exclusive Oplock granted on inode %p"
,
file
->
f_path
.
dentry
->
d_inode
);
}
else
if
((
oplock
&
0xF
)
==
OPLOCK_READ
)
{
pCifsInode
->
clientCanCacheRead
=
true
;
pCifsInode
->
clientCanCacheAll
=
false
;
}
else
{
pCifsInode
->
clientCanCacheRead
=
false
;
pCifsInode
->
clientCanCacheAll
=
false
;
}
cifs_set_oplock_level
(
pCifsInode
,
oplock
);
cifs_relock_file
(
pCifsFile
);
}
}
...
...
@@ -636,10 +608,14 @@ int cifs_close(struct inode *inode, struct file *file)
read_lock
(
&
GlobalSMBSeslock
);
if
(
list_empty
(
&
(
CIFS_I
(
inode
)
->
openFileList
)))
{
cFYI
(
1
,
"closing last open instance for inode %p"
,
inode
);
/* in strict cache mode we need invalidate mapping on the last
close because it may cause a error when we open this file
again and get at least level II oplock */
if
(
cifs_sb
->
mnt_cifs_flags
&
CIFS_MOUNT_STRICT_IO
)
CIFS_I
(
inode
)
->
invalid_mapping
=
true
;
/* if the file is not open we do not know if we can cache info
on this inode, much less write behind and read ahead */
CIFS_I
(
inode
)
->
clientCanCacheRead
=
false
;
CIFS_I
(
inode
)
->
clientCanCacheAll
=
false
;
cifs_set_oplock_level
(
CIFS_I
(
inode
),
0
);
}
read_unlock
(
&
GlobalSMBSeslock
);
if
((
rc
==
0
)
&&
CIFS_I
(
inode
)
->
write_behind_rc
)
...
...
@@ -946,7 +922,7 @@ cifs_write_timeout(struct cifsInodeInfo *cifsi, loff_t offset)
}
/* update the file size (if needed) after a write */
static
void
void
cifs_update_eof
(
struct
cifsInodeInfo
*
cifsi
,
loff_t
offset
,
unsigned
int
bytes_written
)
{
...
...
@@ -1516,6 +1492,7 @@ retry:
break
;
}
if
(
n_iov
)
{
retry_write:
/* Search for a writable handle every time we call
* CIFSSMBWrite2. We can't rely on the last handle
* we used to still be valid
...
...
@@ -1537,36 +1514,55 @@ retry:
&
bytes_written
,
iov
,
n_iov
,
long_op
);
cifsFileInfo_put
(
open_file
);
cifs_update_eof
(
cifsi
,
offset
,
bytes_written
);
}
if
(
rc
||
bytes_written
<
bytes_to_write
)
{
cERROR
(
1
,
"Write2 ret %d, wrote %d"
,
rc
,
bytes_written
);
/* BB what if continued retry is
requested via mount flags? */
if
(
rc
==
-
ENOSPC
)
set_bit
(
AS_ENOSPC
,
&
mapping
->
flags
);
else
set_bit
(
AS_EIO
,
&
mapping
->
flags
);
}
else
{
cifs_stats_bytes_written
(
cifs_sb
->
tcon
,
bytes_written
);
}
cFYI
(
1
,
"Write2 rc=%d, wrote=%u"
,
rc
,
bytes_written
);
/*
* For now, treat a short write as if nothing got
* written. A zero length write however indicates
* ENOSPC or EFBIG. We have no way to know which
* though, so call it ENOSPC for now. EFBIG would
* get translated to AS_EIO anyway.
*
* FIXME: make it take into account the data that did
* get written
*/
if
(
rc
==
0
)
{
if
(
bytes_written
==
0
)
rc
=
-
ENOSPC
;
else
if
(
bytes_written
<
bytes_to_write
)
rc
=
-
EAGAIN
;
}
/* retry on data-integrity flush */
if
(
wbc
->
sync_mode
==
WB_SYNC_ALL
&&
rc
==
-
EAGAIN
)
goto
retry_write
;
/* fix the stats and EOF */
if
(
bytes_written
>
0
)
{
cifs_stats_bytes_written
(
cifs_sb
->
tcon
,
bytes_written
);
cifs_update_eof
(
cifsi
,
offset
,
bytes_written
);
}
for
(
i
=
0
;
i
<
n_iov
;
i
++
)
{
page
=
pvec
.
pages
[
first
+
i
];
/* Should we also set page error on
success rc but too little data written? */
/* BB investigate retry logic on temporary
server crash cases and how recovery works
when page marked as error */
if
(
rc
)
/* on retryable write error, redirty page */
if
(
rc
==
-
EAGAIN
)
redirty_page_for_writepage
(
wbc
,
page
);
else
if
(
rc
!=
0
)
SetPageError
(
page
);
kunmap
(
page
);
unlock_page
(
page
);
end_page_writeback
(
page
);
page_cache_release
(
page
);
}
if
(
rc
!=
-
EAGAIN
)
mapping_set_error
(
mapping
,
rc
);
else
rc
=
0
;
if
((
wbc
->
nr_to_write
-=
n_iov
)
<=
0
)
done
=
1
;
index
=
next
;
...
...
@@ -1677,7 +1673,7 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
return
rc
;
}
int
cifs_fsync
(
struct
file
*
file
,
int
datasync
)
int
cifs_
strict_
fsync
(
struct
file
*
file
,
int
datasync
)
{
int
xid
;
int
rc
=
0
;
...
...
@@ -1685,21 +1681,40 @@ int cifs_fsync(struct file *file, int datasync)
struct
cifsFileInfo
*
smbfile
=
(
struct
cifsFileInfo
*
)
file
->
private_data
;
struct
inode
*
inode
=
file
->
f_path
.
dentry
->
d_inode
;
struct
cifs_sb_info
*
cifs_sb
=
CIFS_SB
(
inode
->
i_sb
);
xid
=
GetXid
();
cFYI
(
1
,
"Sync file - name: %s datasync: 0x%x"
,
file
->
f_path
.
dentry
->
d_name
.
name
,
datasync
);
rc
=
filemap_write_and_wait
(
inode
->
i_mapping
);
if
(
rc
==
0
)
{
rc
=
CIFS_I
(
inode
)
->
write_behind_rc
;
CIFS_I
(
inode
)
->
write_behind_rc
=
0
;
tcon
=
CIFS_SB
(
inode
->
i_sb
)
->
tcon
;
if
(
!
rc
&&
tcon
&&
smbfile
&&
!
(
CIFS_SB
(
inode
->
i_sb
)
->
mnt_cifs_flags
&
CIFS_MOUNT_NOSSYNC
))
rc
=
CIFSSMBFlush
(
xid
,
tcon
,
smbfile
->
netfid
);
}
if
(
!
CIFS_I
(
inode
)
->
clientCanCacheRead
)
cifs_invalidate_mapping
(
inode
);
tcon
=
cifs_sb
->
tcon
;
if
(
!
(
cifs_sb
->
mnt_cifs_flags
&
CIFS_MOUNT_NOSSYNC
))
rc
=
CIFSSMBFlush
(
xid
,
tcon
,
smbfile
->
netfid
);
FreeXid
(
xid
);
return
rc
;
}
int
cifs_fsync
(
struct
file
*
file
,
int
datasync
)
{
int
xid
;
int
rc
=
0
;
struct
cifsTconInfo
*
tcon
;
struct
cifsFileInfo
*
smbfile
=
file
->
private_data
;
struct
cifs_sb_info
*
cifs_sb
=
CIFS_SB
(
file
->
f_path
.
dentry
->
d_sb
);
xid
=
GetXid
();
cFYI
(
1
,
"Sync file - name: %s datasync: 0x%x"
,
file
->
f_path
.
dentry
->
d_name
.
name
,
datasync
);
tcon
=
cifs_sb
->
tcon
;
if
(
!
(
cifs_sb
->
mnt_cifs_flags
&
CIFS_MOUNT_NOSSYNC
))
rc
=
CIFSSMBFlush
(
xid
,
tcon
,
smbfile
->
netfid
);
FreeXid
(
xid
);
return
rc
;
...
...
@@ -1763,21 +1778,247 @@ int cifs_flush(struct file *file, fl_owner_t id)
return
rc
;
}
s
size_t
cifs_user_read
(
struct
file
*
file
,
char
__user
*
read_data
,
size_t
read_size
,
loff_t
*
poffset
)
s
tatic
int
cifs_write_allocate_pages
(
struct
page
**
pages
,
unsigned
long
num_pages
)
{
int
rc
=
-
EACCES
;
int
rc
=
0
;
unsigned
long
i
;
for
(
i
=
0
;
i
<
num_pages
;
i
++
)
{
pages
[
i
]
=
alloc_page
(
__GFP_HIGHMEM
);
if
(
!
pages
[
i
])
{
/*
* save number of pages we have already allocated and
* return with ENOMEM error
*/
num_pages
=
i
;
rc
=
-
ENOMEM
;
goto
error
;
}
}
return
rc
;
error:
for
(
i
=
0
;
i
<
num_pages
;
i
++
)
put_page
(
pages
[
i
]);
return
rc
;
}
static
inline
size_t
get_numpages
(
const
size_t
wsize
,
const
size_t
len
,
size_t
*
cur_len
)
{
size_t
num_pages
;
size_t
clen
;
clen
=
min_t
(
const
size_t
,
len
,
wsize
);
num_pages
=
clen
/
PAGE_CACHE_SIZE
;
if
(
clen
%
PAGE_CACHE_SIZE
)
num_pages
++
;
if
(
cur_len
)
*
cur_len
=
clen
;
return
num_pages
;
}
static
ssize_t
cifs_iovec_write
(
struct
file
*
file
,
const
struct
iovec
*
iov
,
unsigned
long
nr_segs
,
loff_t
*
poffset
)
{
unsigned
int
written
;
unsigned
long
num_pages
,
npages
,
i
;
size_t
copied
,
len
,
cur_len
;
ssize_t
total_written
=
0
;
struct
kvec
*
to_send
;
struct
page
**
pages
;
struct
iov_iter
it
;
struct
inode
*
inode
;
struct
cifsFileInfo
*
open_file
;
struct
cifsTconInfo
*
pTcon
;
struct
cifs_sb_info
*
cifs_sb
;
int
xid
,
rc
;
__u32
netpid
;
len
=
iov_length
(
iov
,
nr_segs
);
if
(
!
len
)
return
0
;
rc
=
generic_write_checks
(
file
,
poffset
,
&
len
,
0
);
if
(
rc
)
return
rc
;
cifs_sb
=
CIFS_SB
(
file
->
f_path
.
dentry
->
d_sb
);
num_pages
=
get_numpages
(
cifs_sb
->
wsize
,
len
,
&
cur_len
);
pages
=
kmalloc
(
sizeof
(
struct
pages
*
)
*
num_pages
,
GFP_KERNEL
);
if
(
!
pages
)
return
-
ENOMEM
;
to_send
=
kmalloc
(
sizeof
(
struct
kvec
)
*
(
num_pages
+
1
),
GFP_KERNEL
);
if
(
!
to_send
)
{
kfree
(
pages
);
return
-
ENOMEM
;
}
rc
=
cifs_write_allocate_pages
(
pages
,
num_pages
);
if
(
rc
)
{
kfree
(
pages
);
kfree
(
to_send
);
return
rc
;
}
xid
=
GetXid
();
if
(
file
->
private_data
==
NULL
)
{
rc
=
-
EBADF
;
for
(
i
=
0
;
i
<
num_pages
;
i
++
)
put_page
(
pages
[
i
]);
kfree
(
pages
);
kfree
(
to_send
);
FreeXid
(
xid
);
return
rc
;
}
open_file
=
file
->
private_data
;
pTcon
=
cifs_sb
->
tcon
;
inode
=
file
->
f_path
.
dentry
->
d_inode
;
if
(
cifs_sb
->
mnt_cifs_flags
&
CIFS_MOUNT_WINE_MODE
)
netpid
=
open_file
->
pid
;
else
netpid
=
current
->
tgid
;
iov_iter_init
(
&
it
,
iov
,
nr_segs
,
len
,
0
);
npages
=
num_pages
;
do
{
size_t
save_len
=
cur_len
;
for
(
i
=
0
;
i
<
npages
;
i
++
)
{
copied
=
min_t
(
const
size_t
,
cur_len
,
PAGE_CACHE_SIZE
);
copied
=
iov_iter_copy_from_user
(
pages
[
i
],
&
it
,
0
,
copied
);
cur_len
-=
copied
;
iov_iter_advance
(
&
it
,
copied
);
to_send
[
i
+
1
].
iov_base
=
kmap
(
pages
[
i
]);
to_send
[
i
+
1
].
iov_len
=
copied
;
}
cur_len
=
save_len
-
cur_len
;
do
{
if
(
open_file
->
invalidHandle
)
{
rc
=
cifs_reopen_file
(
file
,
false
);
if
(
rc
!=
0
)
break
;
}
rc
=
CIFSSMBWrite2
(
xid
,
pTcon
,
open_file
->
netfid
,
netpid
,
cur_len
,
*
poffset
,
&
written
,
to_send
,
npages
,
0
);
}
while
(
rc
==
-
EAGAIN
);
for
(
i
=
0
;
i
<
npages
;
i
++
)
kunmap
(
pages
[
i
]);
if
(
written
)
{
len
-=
written
;
total_written
+=
written
;
cifs_update_eof
(
CIFS_I
(
inode
),
*
poffset
,
written
);
*
poffset
+=
written
;
}
else
if
(
rc
<
0
)
{
if
(
!
total_written
)
total_written
=
rc
;
break
;
}
/* get length and number of kvecs of the next write */
npages
=
get_numpages
(
cifs_sb
->
wsize
,
len
,
&
cur_len
);
}
while
(
len
>
0
);
if
(
total_written
>
0
)
{
spin_lock
(
&
inode
->
i_lock
);
if
(
*
poffset
>
inode
->
i_size
)
i_size_write
(
inode
,
*
poffset
);
spin_unlock
(
&
inode
->
i_lock
);
}
cifs_stats_bytes_written
(
pTcon
,
total_written
);
mark_inode_dirty_sync
(
inode
);
for
(
i
=
0
;
i
<
num_pages
;
i
++
)
put_page
(
pages
[
i
]);
kfree
(
to_send
);
kfree
(
pages
);
FreeXid
(
xid
);
return
total_written
;
}
static
ssize_t
cifs_user_writev
(
struct
kiocb
*
iocb
,
const
struct
iovec
*
iov
,
unsigned
long
nr_segs
,
loff_t
pos
)
{
ssize_t
written
;
struct
inode
*
inode
;
inode
=
iocb
->
ki_filp
->
f_path
.
dentry
->
d_inode
;
/*
* BB - optimize the way when signing is disabled. We can drop this
* extra memory-to-memory copying and use iovec buffers for constructing
* write request.
*/
written
=
cifs_iovec_write
(
iocb
->
ki_filp
,
iov
,
nr_segs
,
&
pos
);
if
(
written
>
0
)
{
CIFS_I
(
inode
)
->
invalid_mapping
=
true
;
iocb
->
ki_pos
=
pos
;
}
return
written
;
}
ssize_t
cifs_strict_writev
(
struct
kiocb
*
iocb
,
const
struct
iovec
*
iov
,
unsigned
long
nr_segs
,
loff_t
pos
)
{
struct
inode
*
inode
;
inode
=
iocb
->
ki_filp
->
f_path
.
dentry
->
d_inode
;
if
(
CIFS_I
(
inode
)
->
clientCanCacheAll
)
return
generic_file_aio_write
(
iocb
,
iov
,
nr_segs
,
pos
);
/*
* In strict cache mode we need to write the data to the server exactly
* from the pos to pos+len-1 rather than flush all affected pages
* because it may cause a error with mandatory locks on these pages but
* not on the region from pos to ppos+len-1.
*/
return
cifs_user_writev
(
iocb
,
iov
,
nr_segs
,
pos
);
}
static
ssize_t
cifs_iovec_read
(
struct
file
*
file
,
const
struct
iovec
*
iov
,
unsigned
long
nr_segs
,
loff_t
*
poffset
)
{
int
rc
;
int
xid
;
ssize_t
total_read
;
unsigned
int
bytes_read
=
0
;
unsigned
int
total_read
=
0
;
unsigned
int
current_read_size
;
size_t
len
,
cur_len
;
int
iov_offset
=
0
;
struct
cifs_sb_info
*
cifs_sb
;
struct
cifsTconInfo
*
pTcon
;
int
xid
;
struct
cifsFileInfo
*
open_file
;
char
*
smb_read_data
;
char
__user
*
current_offset
;
struct
smb_com_read_rsp
*
pSMBr
;
__u32
netpid
;
char
*
read_data
;
if
(
!
nr_segs
)
return
0
;
len
=
iov_length
(
iov
,
nr_segs
);
if
(
!
len
)
return
0
;
xid
=
GetXid
();
cifs_sb
=
CIFS_SB
(
file
->
f_path
.
dentry
->
d_sb
);
...
...
@@ -1798,13 +2039,11 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
if
((
file
->
f_flags
&
O_ACCMODE
)
==
O_WRONLY
)
cFYI
(
1
,
"attempting read on write only file instance"
);
for
(
total_read
=
0
,
current_offset
=
read_data
;
read_size
>
total_read
;
total_read
+=
bytes_read
,
current_offset
+=
bytes_read
)
{
current_read_size
=
min_t
(
const
int
,
read_size
-
total_read
,
cifs_sb
->
rsize
);
for
(
total_read
=
0
;
total_read
<
len
;
total_read
+=
bytes_read
)
{
cur_len
=
min_t
(
const
size_t
,
len
-
total_read
,
cifs_sb
->
rsize
);
rc
=
-
EAGAIN
;
smb_read_data
=
NULL
;
read_data
=
NULL
;
while
(
rc
==
-
EAGAIN
)
{
int
buf_type
=
CIFS_NO_BUFFER
;
if
((
open_file
->
invalidHandle
)
&&
...
...
@@ -1813,27 +2052,25 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
if
(
rc
!=
0
)
break
;
}
rc
=
CIFSSMBRead
(
xid
,
pTcon
,
open_file
->
netfid
,
netpid
,
current_read_size
,
*
poffset
,
&
bytes_read
,
&
smb_read_data
,
&
buf_type
);
pSMBr
=
(
struct
smb_com_read_rsp
*
)
smb_read_data
;
if
(
smb_read_data
)
{
if
(
copy_to_user
(
current_offset
,
smb_read_data
+
4
/* RFC1001 length field */
+
le16_to_cpu
(
pSMBr
->
DataOffset
),
bytes_read
))
rc
=
CIFSSMBRead
(
xid
,
pTcon
,
open_file
->
netfid
,
netpid
,
cur_len
,
*
poffset
,
&
bytes_read
,
&
read_data
,
&
buf_type
);
pSMBr
=
(
struct
smb_com_read_rsp
*
)
read_data
;
if
(
read_data
)
{
char
*
data_offset
=
read_data
+
4
+
le16_to_cpu
(
pSMBr
->
DataOffset
);
if
(
memcpy_toiovecend
(
iov
,
data_offset
,
iov_offset
,
bytes_read
))
rc
=
-
EFAULT
;
if
(
buf_type
==
CIFS_SMALL_BUFFER
)
cifs_small_buf_release
(
smb_
read_data
);
cifs_small_buf_release
(
read_data
);
else
if
(
buf_type
==
CIFS_LARGE_BUFFER
)
cifs_buf_release
(
smb_read_data
);
smb_read_data
=
NULL
;
cifs_buf_release
(
read_data
);
read_data
=
NULL
;
iov_offset
+=
bytes_read
;
}
}
if
(
rc
||
(
bytes_read
==
0
))
{
if
(
total_read
)
{
break
;
...
...
@@ -1846,13 +2083,57 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
*
poffset
+=
bytes_read
;
}
}
FreeXid
(
xid
);
return
total_read
;
}
ssize_t
cifs_user_read
(
struct
file
*
file
,
char
__user
*
read_data
,
size_t
read_size
,
loff_t
*
poffset
)
{
struct
iovec
iov
;
iov
.
iov_base
=
read_data
;
iov
.
iov_len
=
read_size
;
return
cifs_iovec_read
(
file
,
&
iov
,
1
,
poffset
);
}
static
ssize_t
cifs_user_readv
(
struct
kiocb
*
iocb
,
const
struct
iovec
*
iov
,
unsigned
long
nr_segs
,
loff_t
pos
)
{
ssize_t
read
;
read
=
cifs_iovec_read
(
iocb
->
ki_filp
,
iov
,
nr_segs
,
&
pos
);
if
(
read
>
0
)
iocb
->
ki_pos
=
pos
;
return
read
;
}
ssize_t
cifs_strict_readv
(
struct
kiocb
*
iocb
,
const
struct
iovec
*
iov
,
unsigned
long
nr_segs
,
loff_t
pos
)
{
struct
inode
*
inode
;
inode
=
iocb
->
ki_filp
->
f_path
.
dentry
->
d_inode
;
if
(
CIFS_I
(
inode
)
->
clientCanCacheRead
)
return
generic_file_aio_read
(
iocb
,
iov
,
nr_segs
,
pos
);
/*
* In strict cache mode we need to read from the server all the time
* if we don't have level II oplock because the server can delay mtime
* change - so we can't make a decision about inode invalidating.
* And we can also fail with pagereading if there are mandatory locks
* on pages affected by this read but not on the region from pos to
* pos+len-1.
*/
return
cifs_user_readv
(
iocb
,
iov
,
nr_segs
,
pos
);
}
static
ssize_t
cifs_read
(
struct
file
*
file
,
char
*
read_data
,
size_t
read_size
,
loff_t
*
poffset
)
loff_t
*
poffset
)
{
int
rc
=
-
EACCES
;
unsigned
int
bytes_read
=
0
;
...
...
@@ -1927,6 +2208,21 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
return
total_read
;
}
int
cifs_file_strict_mmap
(
struct
file
*
file
,
struct
vm_area_struct
*
vma
)
{
int
rc
,
xid
;
struct
inode
*
inode
=
file
->
f_path
.
dentry
->
d_inode
;
xid
=
GetXid
();
if
(
!
CIFS_I
(
inode
)
->
clientCanCacheRead
)
cifs_invalidate_mapping
(
inode
);
rc
=
generic_file_mmap
(
file
,
vma
);
FreeXid
(
xid
);
return
rc
;
}
int
cifs_file_mmap
(
struct
file
*
file
,
struct
vm_area_struct
*
vma
)
{
int
rc
,
xid
;
...
...
sources/2.6.35/inode.c
View file @
f87f60b3
...
...
@@ -43,13 +43,17 @@ static void cifs_set_ops(struct inode *inode, const bool is_dfs_referral)
inode
->
i_fop
=
&
cifs_file_direct_nobrl_ops
;
else
inode
->
i_fop
=
&
cifs_file_direct_ops
;
}
else
if
(
cifs_sb
->
mnt_cifs_flags
&
CIFS_MOUNT_STRICT_IO
)
{
if
(
cifs_sb
->
mnt_cifs_flags
&
CIFS_MOUNT_NO_BRL
)
inode
->
i_fop
=
&
cifs_file_strict_nobrl_ops
;
else
inode
->
i_fop
=
&
cifs_file_strict_ops
;
}
else
if
(
cifs_sb
->
mnt_cifs_flags
&
CIFS_MOUNT_NO_BRL
)
inode
->
i_fop
=
&
cifs_file_nobrl_ops
;
else
{
/* not direct, send byte range locks */
inode
->
i_fop
=
&
cifs_file_ops
;
}
/* check if server can support readpages */
if
(
cifs_sb
->
tcon
->
ses
->
server
->
maxBuf
<
PAGE_CACHE_SIZE
+
MAX_CIFS_HDR_SIZE
)
...
...
@@ -1552,8 +1556,10 @@ cifs_inode_needs_reval(struct inode *inode)
return
false
;
}
/* check invalid_mapping flag and zap the cache if it's set */
static
void
/*
* Zap the cache. Called when invalid_mapping flag is set.
*/
void
cifs_invalidate_mapping
(
struct
inode
*
inode
)
{
int
rc
;
...
...
@@ -1566,8 +1572,13 @@ cifs_invalidate_mapping(struct inode *inode)
rc
=
filemap_write_and_wait
(
inode
->
i_mapping
);
if
(
rc
)
cifs_i
->
write_behind_rc
=
rc
;
rc
=
invalidate_inode_pages2
(
inode
->
i_mapping
);
if
(
rc
)
{
cERROR
(
1
,
"%s: could not invalidate inode %p"
,
__func__
,
inode
);
cifs_i
->
invalid_mapping
=
true
;
}
}
invalidate_remote_inode
(
inode
);
}
int
cifs_revalidate_file
(
struct
file
*
filp
)
...
...
sources/2.6.35/misc.c
View file @
f87f60b3
...
...
@@ -568,6 +568,10 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
if
(
pSMB
->
Fid
!=
netfile
->
netfid
)
continue
;
cFYI
(
1
,
"file id match, oplock break"
);
pCifsInode
=
CIFS_I
(
netfile
->
pInode
);
cifs_set_oplock_level
(
pCifsInode
,
pSMB
->
OplockLevel
?
OPLOCK_READ
:
0
);
/*
* don't do anything if file is about to be
* closed anyway.
...
...
@@ -578,11 +582,6 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
return
true
;
}
cFYI
(
1
,
"file id match, oplock break"
);
pCifsInode
=
CIFS_I
(
netfile
->
pInode
);
pCifsInode
->
clientCanCacheAll
=
false
;
if
(
pSMB
->
OplockLevel
==
0
)
pCifsInode
->
clientCanCacheRead
=
false
;
rc
=
slow_work_enqueue
(
&
netfile
->
oplock_break
);
if
(
rc
)
{
cERROR
(
1
,
"failed to enqueue oplock "
...
...
@@ -728,3 +727,23 @@ cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb)
cifs_sb
->
tcon
->
treeName
);
}
}
void
cifs_set_oplock_level
(
struct
cifsInodeInfo
*
cinode
,
__u32
oplock
)
{
oplock
&=
0xF
;
if
(
oplock
==
OPLOCK_EXCLUSIVE
)
{
cinode
->
clientCanCacheAll
=
true
;
cinode
->
clientCanCacheRead
=
true
;
cFYI
(
1
,
"Exclusive Oplock granted on inode %p"
,
&
cinode
->
vfs_inode
);
}
else
if
(
oplock
==
OPLOCK_READ
)
{
cinode
->
clientCanCacheAll
=
false
;
cinode
->
clientCanCacheRead
=
true
;
cFYI
(
1
,
"Level II Oplock granted on inode %p"
,
&
cinode
->
vfs_inode
);
}
else
{
cinode
->
clientCanCacheAll
=
false
;
cinode
->
clientCanCacheRead
=
false
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment