Skip to content

Commit c8c081b

Browse files
kinglongmeeJ. Bruce Fields
authored andcommitted
sunrpc/nfsd: Remove redundant code by exports seq_operations functions
Nfsd has implement a site of seq_operations functions as sunrpc's cache. Just exports sunrpc's codes, and remove nfsd's redundant codes. v8, same as v6 Signed-off-by: Kinglong Mee <[email protected]> Reviewed-by: NeilBrown <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent 9936f2a commit c8c081b

File tree

3 files changed

+17
-76
lines changed

3 files changed

+17
-76
lines changed

fs/nfsd/export.c

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,73 +1075,6 @@ exp_pseudoroot(struct svc_rqst *rqstp, struct svc_fh *fhp)
10751075
return rv;
10761076
}
10771077

1078-
/* Iterator */
1079-
1080-
static void *e_start(struct seq_file *m, loff_t *pos)
1081-
__acquires(((struct cache_detail *)m->private)->hash_lock)
1082-
{
1083-
loff_t n = *pos;
1084-
unsigned hash, export;
1085-
struct cache_head *ch;
1086-
struct cache_detail *cd = m->private;
1087-
struct cache_head **export_table = cd->hash_table;
1088-
1089-
read_lock(&cd->hash_lock);
1090-
if (!n--)
1091-
return SEQ_START_TOKEN;
1092-
hash = n >> 32;
1093-
export = n & ((1LL<<32) - 1);
1094-
1095-
1096-
for (ch=export_table[hash]; ch; ch=ch->next)
1097-
if (!export--)
1098-
return ch;
1099-
n &= ~((1LL<<32) - 1);
1100-
do {
1101-
hash++;
1102-
n += 1LL<<32;
1103-
} while(hash < EXPORT_HASHMAX && export_table[hash]==NULL);
1104-
if (hash >= EXPORT_HASHMAX)
1105-
return NULL;
1106-
*pos = n+1;
1107-
return export_table[hash];
1108-
}
1109-
1110-
static void *e_next(struct seq_file *m, void *p, loff_t *pos)
1111-
{
1112-
struct cache_head *ch = p;
1113-
int hash = (*pos >> 32);
1114-
struct cache_detail *cd = m->private;
1115-
struct cache_head **export_table = cd->hash_table;
1116-
1117-
if (p == SEQ_START_TOKEN)
1118-
hash = 0;
1119-
else if (ch->next == NULL) {
1120-
hash++;
1121-
*pos += 1LL<<32;
1122-
} else {
1123-
++*pos;
1124-
return ch->next;
1125-
}
1126-
*pos &= ~((1LL<<32) - 1);
1127-
while (hash < EXPORT_HASHMAX && export_table[hash] == NULL) {
1128-
hash++;
1129-
*pos += 1LL<<32;
1130-
}
1131-
if (hash >= EXPORT_HASHMAX)
1132-
return NULL;
1133-
++*pos;
1134-
return export_table[hash];
1135-
}
1136-
1137-
static void e_stop(struct seq_file *m, void *p)
1138-
__releases(((struct cache_detail *)m->private)->hash_lock)
1139-
{
1140-
struct cache_detail *cd = m->private;
1141-
1142-
read_unlock(&cd->hash_lock);
1143-
}
1144-
11451078
static struct flags {
11461079
int flag;
11471080
char *name[2];
@@ -1270,9 +1203,9 @@ static int e_show(struct seq_file *m, void *p)
12701203
}
12711204

12721205
const struct seq_operations nfs_exports_op = {
1273-
.start = e_start,
1274-
.next = e_next,
1275-
.stop = e_stop,
1206+
.start = cache_seq_start,
1207+
.next = cache_seq_next,
1208+
.stop = cache_seq_stop,
12761209
.show = e_show,
12771210
};
12781211

include/linux/sunrpc/cache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ extern int sunrpc_cache_register_pipefs(struct dentry *parent, const char *,
224224
umode_t, struct cache_detail *);
225225
extern void sunrpc_cache_unregister_pipefs(struct cache_detail *);
226226

227+
/* Must store cache_detail in seq_file->private if using next three functions */
228+
extern void *cache_seq_start(struct seq_file *file, loff_t *pos);
229+
extern void *cache_seq_next(struct seq_file *file, void *p, loff_t *pos);
230+
extern void cache_seq_stop(struct seq_file *file, void *p);
231+
227232
extern void qword_add(char **bpp, int *lp, char *str);
228233
extern void qword_addhex(char **bpp, int *lp, char *buf, int blen);
229234
extern int qword_get(char **bpp, char *dest, int bufsize);

net/sunrpc/cache.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ EXPORT_SYMBOL_GPL(qword_get);
12701270
* get a header, then pass each real item in the cache
12711271
*/
12721272

1273-
static void *c_start(struct seq_file *m, loff_t *pos)
1273+
void *cache_seq_start(struct seq_file *m, loff_t *pos)
12741274
__acquires(cd->hash_lock)
12751275
{
12761276
loff_t n = *pos;
@@ -1298,8 +1298,9 @@ static void *c_start(struct seq_file *m, loff_t *pos)
12981298
*pos = n+1;
12991299
return cd->hash_table[hash];
13001300
}
1301+
EXPORT_SYMBOL_GPL(cache_seq_start);
13011302

1302-
static void *c_next(struct seq_file *m, void *p, loff_t *pos)
1303+
void *cache_seq_next(struct seq_file *m, void *p, loff_t *pos)
13031304
{
13041305
struct cache_head *ch = p;
13051306
int hash = (*pos >> 32);
@@ -1325,13 +1326,15 @@ static void *c_next(struct seq_file *m, void *p, loff_t *pos)
13251326
++*pos;
13261327
return cd->hash_table[hash];
13271328
}
1329+
EXPORT_SYMBOL_GPL(cache_seq_next);
13281330

1329-
static void c_stop(struct seq_file *m, void *p)
1331+
void cache_seq_stop(struct seq_file *m, void *p)
13301332
__releases(cd->hash_lock)
13311333
{
13321334
struct cache_detail *cd = m->private;
13331335
read_unlock(&cd->hash_lock);
13341336
}
1337+
EXPORT_SYMBOL_GPL(cache_seq_stop);
13351338

13361339
static int c_show(struct seq_file *m, void *p)
13371340
{
@@ -1359,9 +1362,9 @@ static int c_show(struct seq_file *m, void *p)
13591362
}
13601363

13611364
static const struct seq_operations cache_content_op = {
1362-
.start = c_start,
1363-
.next = c_next,
1364-
.stop = c_stop,
1365+
.start = cache_seq_start,
1366+
.next = cache_seq_next,
1367+
.stop = cache_seq_stop,
13651368
.show = c_show,
13661369
};
13671370

0 commit comments

Comments
 (0)