Commit cca195c5 authored by Steven Whitehouse's avatar Steven Whitehouse

[GFS2] Extended attribute code style changes

As per Jan Engelhardt's request and also a few of my own. It has
been possible to add a few most const to the code as a result of
the change in gfs2_ea_name2type.

Cc: Jan Engelhardt <jengelh@linux01.gwdg.de>
Signed-off-by: default avatarSteven Whitehouse <swhiteho@redhat.com>
parent 16910427
...@@ -31,22 +31,22 @@ ...@@ -31,22 +31,22 @@
* Returns: GFS2_EATYPE_XXX * Returns: GFS2_EATYPE_XXX
*/ */
unsigned int gfs2_ea_name2type(const char *name, char **truncated_name) unsigned int gfs2_ea_name2type(const char *name, const char **truncated_name)
{ {
unsigned int type; unsigned int type;
if (strncmp(name, "system.", 7) == 0) { if (strncmp(name, "system.", 7) == 0) {
type = GFS2_EATYPE_SYS; type = GFS2_EATYPE_SYS;
if (truncated_name) if (truncated_name)
*truncated_name = strchr(name, '.') + 1; *truncated_name = name + sizeof("system.") - 1;
} else if (strncmp(name, "user.", 5) == 0) { } else if (strncmp(name, "user.", 5) == 0) {
type = GFS2_EATYPE_USR; type = GFS2_EATYPE_USR;
if (truncated_name) if (truncated_name)
*truncated_name = strchr(name, '.') + 1; *truncated_name = name + sizeof("user.") - 1;
} else if (strncmp(name, "security.", 9) == 0) { } else if (strncmp(name, "security.", 9) == 0) {
type = GFS2_EATYPE_SECURITY; type = GFS2_EATYPE_SECURITY;
if (truncated_name) if (truncated_name)
*truncated_name = strchr(name, '.') + 1; *truncated_name = name + sizeof("security.") - 1;
} else { } else {
type = GFS2_EATYPE_UNUSED; type = GFS2_EATYPE_UNUSED;
if (truncated_name) if (truncated_name)
......
...@@ -20,7 +20,7 @@ struct gfs2_eattr_operations { ...@@ -20,7 +20,7 @@ struct gfs2_eattr_operations {
char *eo_name; char *eo_name;
}; };
unsigned int gfs2_ea_name2type(const char *name, char **truncated_name); unsigned int gfs2_ea_name2type(const char *name, const char **truncated_name);
extern struct gfs2_eattr_operations gfs2_system_eaops; extern struct gfs2_eattr_operations gfs2_system_eaops;
......
...@@ -68,11 +68,9 @@ static int ea_check_size(struct gfs2_sbd *sdp, struct gfs2_ea_request *er) ...@@ -68,11 +68,9 @@ static int ea_check_size(struct gfs2_sbd *sdp, struct gfs2_ea_request *er)
return 0; return 0;
} }
typedef int (*ea_call_t) (struct gfs2_inode *ip, typedef int (*ea_call_t) (struct gfs2_inode *ip, struct buffer_head *bh,
struct buffer_head *bh,
struct gfs2_ea_header *ea, struct gfs2_ea_header *ea,
struct gfs2_ea_header *prev, struct gfs2_ea_header *prev, void *private);
void *private);
static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh,
ea_call_t ea_call, void *data) ea_call_t ea_call, void *data)
...@@ -86,8 +84,7 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, ...@@ -86,8 +84,7 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh,
for (ea = GFS2_EA_BH2FIRST(bh);; prev = ea, ea = GFS2_EA2NEXT(ea)) { for (ea = GFS2_EA_BH2FIRST(bh);; prev = ea, ea = GFS2_EA2NEXT(ea)) {
if (!GFS2_EA_REC_LEN(ea)) if (!GFS2_EA_REC_LEN(ea))
goto fail; goto fail;
if (!(bh->b_data <= (char *)ea && if (!(bh->b_data <= (char *)ea && (char *)GFS2_EA2NEXT(ea) <=
(char *)GFS2_EA2NEXT(ea) <=
bh->b_data + bh->b_size)) bh->b_data + bh->b_size))
goto fail; goto fail;
if (!GFS2_EATYPE_VALID(ea->ea_type)) if (!GFS2_EATYPE_VALID(ea->ea_type))
...@@ -118,8 +115,7 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) ...@@ -118,8 +115,7 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data)
u64 *eablk, *end; u64 *eablk, *end;
int error; int error;
error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_START | DIO_WAIT, &bh);
DIO_START | DIO_WAIT, &bh);
if (error) if (error)
return error; return error;
...@@ -143,8 +139,7 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) ...@@ -143,8 +139,7 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data)
break; break;
bn = be64_to_cpu(*eablk); bn = be64_to_cpu(*eablk);
error = gfs2_meta_read(ip->i_gl, bn, DIO_START | DIO_WAIT, error = gfs2_meta_read(ip->i_gl, bn, DIO_START | DIO_WAIT, &eabh);
&eabh);
if (error) if (error)
break; break;
error = ea_foreach_i(ip, eabh, ea_call, data); error = ea_foreach_i(ip, eabh, ea_call, data);
...@@ -184,12 +179,6 @@ static int ea_find_i(struct gfs2_inode *ip, struct buffer_head *bh, ...@@ -184,12 +179,6 @@ static int ea_find_i(struct gfs2_inode *ip, struct buffer_head *bh,
} }
} }
#if 0
else if ((ip->i_di.di_flags & GFS2_DIF_EA_PACKED) &&
er->er_type == GFS2_EATYPE_SYS)
return 1;
#endif
return 0; return 0;
} }
...@@ -246,11 +235,12 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, ...@@ -246,11 +235,12 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
return 0; return 0;
dataptrs = GFS2_EA2DATAPTRS(ea); dataptrs = GFS2_EA2DATAPTRS(ea);
for (x = 0; x < ea->ea_num_ptrs; x++, dataptrs++) for (x = 0; x < ea->ea_num_ptrs; x++, dataptrs++) {
if (*dataptrs) { if (*dataptrs) {
blks++; blks++;
bn = be64_to_cpu(*dataptrs); bn = be64_to_cpu(*dataptrs);
} }
}
if (!blks) if (!blks)
return 0; return 0;
...@@ -264,9 +254,8 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, ...@@ -264,9 +254,8 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
if (error) if (error)
return error; return error;
error = gfs2_trans_begin(sdp, rgd->rd_ri.ri_length + error = gfs2_trans_begin(sdp, rgd->rd_ri.ri_length + RES_DINODE +
RES_DINODE + RES_EATTR + RES_STATFS + RES_EATTR + RES_STATFS + RES_QUOTA, blks);
RES_QUOTA, blks);
if (error) if (error)
goto out_gunlock; goto out_gunlock;
...@@ -340,9 +329,7 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, ...@@ -340,9 +329,7 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
if (error) if (error)
goto out_quota; goto out_quota;
error = ea_dealloc_unstuffed(ip, error = ea_dealloc_unstuffed(ip, bh, ea, prev, (leave) ? &error : NULL);
bh, ea, prev,
(leave) ? &error : NULL);
gfs2_glock_dq_uninit(&al->al_ri_gh); gfs2_glock_dq_uninit(&al->al_ri_gh);
...@@ -423,9 +410,7 @@ int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er) ...@@ -423,9 +410,7 @@ int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er)
er->er_data_len = 0; er->er_data_len = 0;
} }
error = gfs2_glock_nq_init(ip->i_gl, error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
LM_ST_SHARED, LM_FLAG_ANY,
&i_gh);
if (error) if (error)
return error; return error;
...@@ -445,9 +430,9 @@ int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er) ...@@ -445,9 +430,9 @@ int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er)
/** /**
* ea_get_unstuffed - actually copies the unstuffed data into the * ea_get_unstuffed - actually copies the unstuffed data into the
* request buffer * request buffer
* @ip: * @ip: The GFS2 inode
* @ea: * @ea: The extended attribute header structure
* @data: * @data: The data to be copied
* *
* Returns: errno * Returns: errno
*/ */
...@@ -492,8 +477,7 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, ...@@ -492,8 +477,7 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
goto out; goto out;
} }
memcpy(data, memcpy(data, bh[x]->b_data + sizeof(struct gfs2_meta_header),
bh[x]->b_data + sizeof(struct gfs2_meta_header),
(sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize);
amount -= sdp->sd_jbsize; amount -= sdp->sd_jbsize;
...@@ -511,9 +495,7 @@ int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el, ...@@ -511,9 +495,7 @@ int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el,
char *data) char *data)
{ {
if (GFS2_EA_IS_STUFFED(el->el_ea)) { if (GFS2_EA_IS_STUFFED(el->el_ea)) {
memcpy(data, memcpy(data, GFS2_EA2DATA(el->el_ea), GFS2_EA_DATA_LEN(el->el_ea));
GFS2_EA2DATA(el->el_ea),
GFS2_EA_DATA_LEN(el->el_ea));
return 0; return 0;
} else } else
return ea_get_unstuffed(ip, el->el_ea, data); return ea_get_unstuffed(ip, el->el_ea, data);
...@@ -521,8 +503,8 @@ int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el, ...@@ -521,8 +503,8 @@ int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el,
/** /**
* gfs2_ea_get_i - * gfs2_ea_get_i -
* @ip: * @ip: The GFS2 inode
* @er: * @er: The request structure
* *
* Returns: actual size of data on success, -errno on error * Returns: actual size of data on success, -errno on error
*/ */
...@@ -557,8 +539,8 @@ int gfs2_ea_get_i(struct gfs2_inode *ip, struct gfs2_ea_request *er) ...@@ -557,8 +539,8 @@ int gfs2_ea_get_i(struct gfs2_inode *ip, struct gfs2_ea_request *er)
/** /**
* gfs2_ea_get - * gfs2_ea_get -
* @ip: * @ip: The GFS2 inode
* @er: * @er: The request structure
* *
* Returns: actual size of data on success, -errno on error * Returns: actual size of data on success, -errno on error
*/ */
...@@ -576,9 +558,7 @@ int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) ...@@ -576,9 +558,7 @@ int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
er->er_data_len = 0; er->er_data_len = 0;
} }
error = gfs2_glock_nq_init(ip->i_gl, error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
LM_ST_SHARED, LM_FLAG_ANY,
&i_gh);
if (error) if (error)
return error; return error;
...@@ -592,7 +572,7 @@ int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) ...@@ -592,7 +572,7 @@ int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
/** /**
* ea_alloc_blk - allocates a new block for extended attributes. * ea_alloc_blk - allocates a new block for extended attributes.
* @ip: A pointer to the inode that's getting extended attributes * @ip: A pointer to the inode that's getting extended attributes
* @bhp: * @bhp: Pointer to pointer to a struct buffer_head
* *
* Returns: errno * Returns: errno
*/ */
...@@ -669,14 +649,14 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, ...@@ -669,14 +649,14 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
ip->i_di.di_blocks++; ip->i_di.di_blocks++;
copy = (data_len > sdp->sd_jbsize) ? sdp->sd_jbsize : copy = data_len > sdp->sd_jbsize ? sdp->sd_jbsize :
data_len; data_len;
memcpy(bh->b_data + mh_size, data, copy); memcpy(bh->b_data + mh_size, data, copy);
if (copy < sdp->sd_jbsize) if (copy < sdp->sd_jbsize)
memset(bh->b_data + mh_size + copy, 0, memset(bh->b_data + mh_size + copy, 0,
sdp->sd_jbsize - copy); sdp->sd_jbsize - copy);
*dataptr++ = cpu_to_be64((u64)bh->b_blocknr); *dataptr++ = cpu_to_be64(bh->b_blocknr);
data += copy; data += copy;
data_len -= copy; data_len -= copy;
...@@ -690,13 +670,11 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, ...@@ -690,13 +670,11 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
} }
typedef int (*ea_skeleton_call_t) (struct gfs2_inode *ip, typedef int (*ea_skeleton_call_t) (struct gfs2_inode *ip,
struct gfs2_ea_request *er, struct gfs2_ea_request *er, void *private);
void *private);
static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er, static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
unsigned int blks, unsigned int blks,
ea_skeleton_call_t skeleton_call, ea_skeleton_call_t skeleton_call, void *private)
void *private)
{ {
struct gfs2_alloc *al; struct gfs2_alloc *al;
struct buffer_head *dibh; struct buffer_head *dibh;
...@@ -1013,7 +991,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, ...@@ -1013,7 +991,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er,
goto out; goto out;
if (private) if (private)
ea_set_remove_stuffed(ip, (struct gfs2_ea_location *)private); ea_set_remove_stuffed(ip, private);
out: out:
brelse(indbh); brelse(indbh);
...@@ -1101,8 +1079,7 @@ int gfs2_ea_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) ...@@ -1101,8 +1079,7 @@ int gfs2_ea_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
struct gfs2_holder i_gh; struct gfs2_holder i_gh;
int error; int error;
if (!er->er_name_len || if (!er->er_name_len || er->er_name_len > GFS2_EA_MAX_NAME_LEN)
er->er_name_len > GFS2_EA_MAX_NAME_LEN)
return -EINVAL; return -EINVAL;
if (!er->er_data || !er->er_data_len) { if (!er->er_data || !er->er_data_len) {
er->er_data = NULL; er->er_data = NULL;
...@@ -1264,8 +1241,7 @@ static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, ...@@ -1264,8 +1241,7 @@ static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip,
gfs2_trans_add_bh(ip->i_gl, bh[x], 1); gfs2_trans_add_bh(ip->i_gl, bh[x], 1);
memcpy(bh[x]->b_data + sizeof(struct gfs2_meta_header), memcpy(bh[x]->b_data + sizeof(struct gfs2_meta_header), data,
data,
(sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize);
amount -= sdp->sd_jbsize; amount -= sdp->sd_jbsize;
...@@ -1296,8 +1272,7 @@ int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el, ...@@ -1296,8 +1272,7 @@ int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el,
return error; return error;
gfs2_trans_add_bh(ip->i_gl, el->el_bh, 1); gfs2_trans_add_bh(ip->i_gl, el->el_bh, 1);
memcpy(GFS2_EA2DATA(el->el_ea), memcpy(GFS2_EA2DATA(el->el_ea), data,
data,
GFS2_EA_DATA_LEN(el->el_ea)); GFS2_EA_DATA_LEN(el->el_ea));
} else } else
error = ea_acl_chmod_unstuffed(ip, el->el_ea, data); error = ea_acl_chmod_unstuffed(ip, el->el_ea, data);
...@@ -1382,9 +1357,8 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip) ...@@ -1382,9 +1357,8 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip)
if (error) if (error)
goto out_rlist_free; goto out_rlist_free;
error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + RES_INDIRECT +
RES_INDIRECT + RES_STATFS + RES_STATFS + RES_QUOTA, blks);
RES_QUOTA, blks);
if (error) if (error)
goto out_gunlock; goto out_gunlock;
...@@ -1457,8 +1431,8 @@ static int ea_dealloc_block(struct gfs2_inode *ip) ...@@ -1457,8 +1431,8 @@ static int ea_dealloc_block(struct gfs2_inode *ip)
if (error) if (error)
return error; return error;
error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_DINODE + error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_DINODE + RES_STATFS +
RES_STATFS + RES_QUOTA, 1); RES_QUOTA, 1);
if (error) if (error)
goto out_gunlock; goto out_gunlock;
......
...@@ -46,7 +46,7 @@ ALIGN(sizeof(struct gfs2_ea_header) + (er)->er_name_len + \ ...@@ -46,7 +46,7 @@ ALIGN(sizeof(struct gfs2_ea_header) + (er)->er_name_len + \
#define GFS2_ERF_MODE 0x80000000 #define GFS2_ERF_MODE 0x80000000
struct gfs2_ea_request { struct gfs2_ea_request {
char *er_name; const char *er_name;
char *er_data; char *er_data;
unsigned int er_name_len; unsigned int er_name_len;
unsigned int er_data_len; unsigned int er_data_len;
...@@ -87,13 +87,13 @@ static inline unsigned int gfs2_ea_strlen(struct gfs2_ea_header *ea) ...@@ -87,13 +87,13 @@ static inline unsigned int gfs2_ea_strlen(struct gfs2_ea_header *ea)
{ {
switch (ea->ea_type) { switch (ea->ea_type) {
case GFS2_EATYPE_USR: case GFS2_EATYPE_USR:
return (5 + (ea->ea_name_len + 1)); return 5 + ea->ea_name_len + 1;
case GFS2_EATYPE_SYS: case GFS2_EATYPE_SYS:
return (7 + (ea->ea_name_len + 1)); return 7 + ea->ea_name_len + 1;
case GFS2_EATYPE_SECURITY: case GFS2_EATYPE_SECURITY:
return (9 + (ea->ea_name_len + 1)); return 9 + ea->ea_name_len + 1;
default: default:
return (0); return 0;
} }
} }
......
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