Commit 235628c5 authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Bob Peterson

gfs2: Add gfs2_max_stuffed_size

Add a small inline function for computing the maximum size of a stuffed
inode instead of open coding that in several places throughout the code.
Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: default avatarBob Peterson <rpeterso@redhat.com>
parent 9db115a0
...@@ -482,8 +482,8 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page) ...@@ -482,8 +482,8 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
return error; return error;
kaddr = kmap_atomic(page); kaddr = kmap_atomic(page);
if (dsize > (dibh->b_size - sizeof(struct gfs2_dinode))) if (dsize > gfs2_max_stuffed_size(ip))
dsize = (dibh->b_size - sizeof(struct gfs2_dinode)); dsize = gfs2_max_stuffed_size(ip);
memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), dsize); memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), dsize);
memset(kaddr + dsize, 0, PAGE_SIZE - dsize); memset(kaddr + dsize, 0, PAGE_SIZE - dsize);
kunmap_atomic(kaddr); kunmap_atomic(kaddr);
...@@ -723,7 +723,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping, ...@@ -723,7 +723,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
if (gfs2_is_stuffed(ip)) { if (gfs2_is_stuffed(ip)) {
error = 0; error = 0;
if (pos + len > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) { if (pos + len > gfs2_max_stuffed_size(ip)) {
error = gfs2_unstuff_dinode(ip, page); error = gfs2_unstuff_dinode(ip, page);
if (error == 0) if (error == 0)
goto prepare_write; goto prepare_write;
...@@ -830,7 +830,8 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh, ...@@ -830,7 +830,8 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,
void *kaddr; void *kaddr;
unsigned char *buf = dibh->b_data + sizeof(struct gfs2_dinode); unsigned char *buf = dibh->b_data + sizeof(struct gfs2_dinode);
BUG_ON((pos + len) > (dibh->b_size - sizeof(struct gfs2_dinode))); BUG_ON(pos + len > gfs2_max_stuffed_size(ip));
kaddr = kmap_atomic(page); kaddr = kmap_atomic(page);
memcpy(buf + pos, kaddr + pos, copied); memcpy(buf + pos, kaddr + pos, copied);
flush_dcache_page(page); flush_dcache_page(page);
......
...@@ -69,8 +69,8 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, ...@@ -69,8 +69,8 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
void *kaddr = kmap(page); void *kaddr = kmap(page);
u64 dsize = i_size_read(inode); u64 dsize = i_size_read(inode);
if (dsize > (dibh->b_size - sizeof(struct gfs2_dinode))) if (dsize > gfs2_max_stuffed_size(ip))
dsize = dibh->b_size - sizeof(struct gfs2_dinode); dsize = gfs2_max_stuffed_size(ip);
memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), dsize); memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), dsize);
memset(kaddr + dsize, 0, PAGE_SIZE - dsize); memset(kaddr + dsize, 0, PAGE_SIZE - dsize);
...@@ -1692,8 +1692,7 @@ static int do_grow(struct inode *inode, u64 size) ...@@ -1692,8 +1692,7 @@ static int do_grow(struct inode *inode, u64 size)
int error; int error;
int unstuff = 0; int unstuff = 0;
if (gfs2_is_stuffed(ip) && if (gfs2_is_stuffed(ip) && size > gfs2_max_stuffed_size(ip)) {
(size > (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)))) {
error = gfs2_quota_lock_check(ip, &ap); error = gfs2_quota_lock_check(ip, &ap);
if (error) if (error)
return error; return error;
...@@ -1928,8 +1927,7 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset, ...@@ -1928,8 +1927,7 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
return 0; return 0;
if (gfs2_is_stuffed(ip)) { if (gfs2_is_stuffed(ip)) {
if (offset + len > if (offset + len > gfs2_max_stuffed_size(ip))
sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode))
return 1; return 1;
return 0; return 0;
} }
......
...@@ -170,8 +170,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, ...@@ -170,8 +170,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf,
if (!size) if (!size)
return 0; return 0;
if (gfs2_is_stuffed(ip) && if (gfs2_is_stuffed(ip) && offset + size <= gfs2_max_stuffed_size(ip))
offset + size <= sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode))
return gfs2_dir_write_stuffed(ip, buf, (unsigned int)offset, return gfs2_dir_write_stuffed(ip, buf, (unsigned int)offset,
size); size);
......
...@@ -861,5 +861,10 @@ static inline void gfs2_sbstats_inc(const struct gfs2_glock *gl, int which) ...@@ -861,5 +861,10 @@ static inline void gfs2_sbstats_inc(const struct gfs2_glock *gl, int which)
extern struct gfs2_rgrpd *gfs2_glock2rgrp(struct gfs2_glock *gl); extern struct gfs2_rgrpd *gfs2_glock2rgrp(struct gfs2_glock *gl);
static inline unsigned gfs2_max_stuffed_size(const struct gfs2_inode *ip)
{
return GFS2_SB(&ip->i_inode)->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
}
#endif /* __INCORE_DOT_H__ */ #endif /* __INCORE_DOT_H__ */
...@@ -1184,11 +1184,10 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry) ...@@ -1184,11 +1184,10 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
static int gfs2_symlink(struct inode *dir, struct dentry *dentry, static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
const char *symname) const char *symname)
{ {
struct gfs2_sbd *sdp = GFS2_SB(dir);
unsigned int size; unsigned int size;
size = strlen(symname); size = strlen(symname);
if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1) if (size >= gfs2_max_stuffed_size(GFS2_I(dir)))
return -ENAMETOOLONG; return -ENAMETOOLONG;
return gfs2_create_inode(dir, dentry, NULL, S_IFLNK | S_IRWXUGO, 0, symname, size, 0, NULL); return gfs2_create_inode(dir, dentry, NULL, S_IFLNK | S_IRWXUGO, 0, symname, size, 0, NULL);
...@@ -1205,8 +1204,7 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry, ...@@ -1205,8 +1204,7 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
{ {
struct gfs2_sbd *sdp = GFS2_SB(dir); unsigned dsize = gfs2_max_stuffed_size(GFS2_I(dir));
unsigned dsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
return gfs2_create_inode(dir, dentry, NULL, S_IFDIR | mode, 0, NULL, dsize, 0, NULL); return gfs2_create_inode(dir, dentry, NULL, S_IFDIR | mode, 0, NULL, dsize, 0, NULL);
} }
......
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