Skip to content

Commit d4b2cf1

Browse files
committed
GFS2: Move gfs2_refresh_inode() and friends into glops.c
Eventually there will only be a single caller of this code, so lets move it where it can be made static at some future date. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent 94fb763 commit d4b2cf1

2 files changed

Lines changed: 113 additions & 117 deletions

File tree

‎fs/gfs2/glops.c‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,119 @@ static int inode_go_demote_ok(const struct gfs2_glock *gl)
251251
return 1;
252252
}
253253

254+
/**
255+
* gfs2_set_nlink - Set the inode's link count based on on-disk info
256+
* @inode: The inode in question
257+
* @nlink: The link count
258+
*
259+
* If the link count has hit zero, it must never be raised, whatever the
260+
* on-disk inode might say. When new struct inodes are created the link
261+
* count is set to 1, so that we can safely use this test even when reading
262+
* in on disk information for the first time.
263+
*/
264+
265+
static void gfs2_set_nlink(struct inode *inode, u32 nlink)
266+
{
267+
/*
268+
* We will need to review setting the nlink count here in the
269+
* light of the forthcoming ro bind mount work. This is a reminder
270+
* to do that.
271+
*/
272+
if ((inode->i_nlink != nlink) && (inode->i_nlink != 0)) {
273+
if (nlink == 0)
274+
clear_nlink(inode);
275+
else
276+
inode->i_nlink = nlink;
277+
}
278+
}
279+
280+
static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
281+
{
282+
const struct gfs2_dinode *str = buf;
283+
struct timespec atime;
284+
u16 height, depth;
285+
286+
if (unlikely(ip->i_no_addr != be64_to_cpu(str->di_num.no_addr)))
287+
goto corrupt;
288+
ip->i_no_formal_ino = be64_to_cpu(str->di_num.no_formal_ino);
289+
ip->i_inode.i_mode = be32_to_cpu(str->di_mode);
290+
ip->i_inode.i_rdev = 0;
291+
switch (ip->i_inode.i_mode & S_IFMT) {
292+
case S_IFBLK:
293+
case S_IFCHR:
294+
ip->i_inode.i_rdev = MKDEV(be32_to_cpu(str->di_major),
295+
be32_to_cpu(str->di_minor));
296+
break;
297+
};
298+
299+
ip->i_inode.i_uid = be32_to_cpu(str->di_uid);
300+
ip->i_inode.i_gid = be32_to_cpu(str->di_gid);
301+
gfs2_set_nlink(&ip->i_inode, be32_to_cpu(str->di_nlink));
302+
i_size_write(&ip->i_inode, be64_to_cpu(str->di_size));
303+
gfs2_set_inode_blocks(&ip->i_inode, be64_to_cpu(str->di_blocks));
304+
atime.tv_sec = be64_to_cpu(str->di_atime);
305+
atime.tv_nsec = be32_to_cpu(str->di_atime_nsec);
306+
if (timespec_compare(&ip->i_inode.i_atime, &atime) < 0)
307+
ip->i_inode.i_atime = atime;
308+
ip->i_inode.i_mtime.tv_sec = be64_to_cpu(str->di_mtime);
309+
ip->i_inode.i_mtime.tv_nsec = be32_to_cpu(str->di_mtime_nsec);
310+
ip->i_inode.i_ctime.tv_sec = be64_to_cpu(str->di_ctime);
311+
ip->i_inode.i_ctime.tv_nsec = be32_to_cpu(str->di_ctime_nsec);
312+
313+
ip->i_goal = be64_to_cpu(str->di_goal_meta);
314+
ip->i_generation = be64_to_cpu(str->di_generation);
315+
316+
ip->i_diskflags = be32_to_cpu(str->di_flags);
317+
gfs2_set_inode_flags(&ip->i_inode);
318+
height = be16_to_cpu(str->di_height);
319+
if (unlikely(height > GFS2_MAX_META_HEIGHT))
320+
goto corrupt;
321+
ip->i_height = (u8)height;
322+
323+
depth = be16_to_cpu(str->di_depth);
324+
if (unlikely(depth > GFS2_DIR_MAX_DEPTH))
325+
goto corrupt;
326+
ip->i_depth = (u8)depth;
327+
ip->i_entries = be32_to_cpu(str->di_entries);
328+
329+
ip->i_eattr = be64_to_cpu(str->di_eattr);
330+
if (S_ISREG(ip->i_inode.i_mode))
331+
gfs2_set_aops(&ip->i_inode);
332+
333+
return 0;
334+
corrupt:
335+
gfs2_consist_inode(ip);
336+
return -EIO;
337+
}
338+
339+
/**
340+
* gfs2_inode_refresh - Refresh the incore copy of the dinode
341+
* @ip: The GFS2 inode
342+
*
343+
* Returns: errno
344+
*/
345+
346+
int gfs2_inode_refresh(struct gfs2_inode *ip)
347+
{
348+
struct buffer_head *dibh;
349+
int error;
350+
351+
error = gfs2_meta_inode_buffer(ip, &dibh);
352+
if (error)
353+
return error;
354+
355+
if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), dibh, GFS2_METATYPE_DI)) {
356+
brelse(dibh);
357+
return -EIO;
358+
}
359+
360+
error = gfs2_dinode_in(ip, dibh->b_data);
361+
brelse(dibh);
362+
clear_bit(GIF_INVALID, &ip->i_flags);
363+
364+
return error;
365+
}
366+
254367
/**
255368
* inode_go_lock - operation done after an inode lock is locked by a process
256369
* @gl: the glock

‎fs/gfs2/inode.c‎

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@
3535
#include "trans.h"
3636
#include "util.h"
3737

38-
struct gfs2_inum_range_host {
39-
u64 ir_start;
40-
u64 ir_length;
41-
};
42-
4338
struct gfs2_skip_data {
4439
u64 no_addr;
4540
int skipped;
@@ -248,118 +243,6 @@ struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
248243
goto fail;
249244
}
250245

251-
/**
252-
* gfs2_set_nlink - Set the inode's link count based on on-disk info
253-
* @inode: The inode in question
254-
* @nlink: The link count
255-
*
256-
* If the link count has hit zero, it must never be raised, whatever the
257-
* on-disk inode might say. When new struct inodes are created the link
258-
* count is set to 1, so that we can safely use this test even when reading
259-
* in on disk information for the first time.
260-
*/
261-
262-
static void gfs2_set_nlink(struct inode *inode, u32 nlink)
263-
{
264-
/*
265-
* We will need to review setting the nlink count here in the
266-
* light of the forthcoming ro bind mount work. This is a reminder
267-
* to do that.
268-
*/
269-
if ((inode->i_nlink != nlink) && (inode->i_nlink != 0)) {
270-
if (nlink == 0)
271-
clear_nlink(inode);
272-
else
273-
inode->i_nlink = nlink;
274-
}
275-
}
276-
277-
static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
278-
{
279-
const struct gfs2_dinode *str = buf;
280-
struct timespec atime;
281-
u16 height, depth;
282-
283-
if (unlikely(ip->i_no_addr != be64_to_cpu(str->di_num.no_addr)))
284-
goto corrupt;
285-
ip->i_no_formal_ino = be64_to_cpu(str->di_num.no_formal_ino);
286-
ip->i_inode.i_mode = be32_to_cpu(str->di_mode);
287-
ip->i_inode.i_rdev = 0;
288-
switch (ip->i_inode.i_mode & S_IFMT) {
289-
case S_IFBLK:
290-
case S_IFCHR:
291-
ip->i_inode.i_rdev = MKDEV(be32_to_cpu(str->di_major),
292-
be32_to_cpu(str->di_minor));
293-
break;
294-
};
295-
296-
ip->i_inode.i_uid = be32_to_cpu(str->di_uid);
297-
ip->i_inode.i_gid = be32_to_cpu(str->di_gid);
298-
gfs2_set_nlink(&ip->i_inode, be32_to_cpu(str->di_nlink));
299-
i_size_write(&ip->i_inode, be64_to_cpu(str->di_size));
300-
gfs2_set_inode_blocks(&ip->i_inode, be64_to_cpu(str->di_blocks));
301-
atime.tv_sec = be64_to_cpu(str->di_atime);
302-
atime.tv_nsec = be32_to_cpu(str->di_atime_nsec);
303-
if (timespec_compare(&ip->i_inode.i_atime, &atime) < 0)
304-
ip->i_inode.i_atime = atime;
305-
ip->i_inode.i_mtime.tv_sec = be64_to_cpu(str->di_mtime);
306-
ip->i_inode.i_mtime.tv_nsec = be32_to_cpu(str->di_mtime_nsec);
307-
ip->i_inode.i_ctime.tv_sec = be64_to_cpu(str->di_ctime);
308-
ip->i_inode.i_ctime.tv_nsec = be32_to_cpu(str->di_ctime_nsec);
309-
310-
ip->i_goal = be64_to_cpu(str->di_goal_meta);
311-
ip->i_generation = be64_to_cpu(str->di_generation);
312-
313-
ip->i_diskflags = be32_to_cpu(str->di_flags);
314-
gfs2_set_inode_flags(&ip->i_inode);
315-
height = be16_to_cpu(str->di_height);
316-
if (unlikely(height > GFS2_MAX_META_HEIGHT))
317-
goto corrupt;
318-
ip->i_height = (u8)height;
319-
320-
depth = be16_to_cpu(str->di_depth);
321-
if (unlikely(depth > GFS2_DIR_MAX_DEPTH))
322-
goto corrupt;
323-
ip->i_depth = (u8)depth;
324-
ip->i_entries = be32_to_cpu(str->di_entries);
325-
326-
ip->i_eattr = be64_to_cpu(str->di_eattr);
327-
if (S_ISREG(ip->i_inode.i_mode))
328-
gfs2_set_aops(&ip->i_inode);
329-
330-
return 0;
331-
corrupt:
332-
gfs2_consist_inode(ip);
333-
return -EIO;
334-
}
335-
336-
/**
337-
* gfs2_inode_refresh - Refresh the incore copy of the dinode
338-
* @ip: The GFS2 inode
339-
*
340-
* Returns: errno
341-
*/
342-
343-
int gfs2_inode_refresh(struct gfs2_inode *ip)
344-
{
345-
struct buffer_head *dibh;
346-
int error;
347-
348-
error = gfs2_meta_inode_buffer(ip, &dibh);
349-
if (error)
350-
return error;
351-
352-
if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), dibh, GFS2_METATYPE_DI)) {
353-
brelse(dibh);
354-
return -EIO;
355-
}
356-
357-
error = gfs2_dinode_in(ip, dibh->b_data);
358-
brelse(dibh);
359-
clear_bit(GIF_INVALID, &ip->i_flags);
360-
361-
return error;
362-
}
363246

364247
struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
365248
{

0 commit comments

Comments
 (0)