Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <kinglongmee@gmail.com>
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>

authored by

Kinglong Mee and committed by
J. Bruce Fields
c8c081b7 9936f2ae

+17 -76
+3 -70
fs/nfsd/export.c
··· 1075 1075 return rv; 1076 1076 } 1077 1077 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 - 1145 1078 static struct flags { 1146 1079 int flag; 1147 1080 char *name[2]; ··· 1203 1270 } 1204 1271 1205 1272 const struct seq_operations nfs_exports_op = { 1206 - .start = e_start, 1207 - .next = e_next, 1208 - .stop = e_stop, 1273 + .start = cache_seq_start, 1274 + .next = cache_seq_next, 1275 + .stop = cache_seq_stop, 1209 1276 .show = e_show, 1210 1277 }; 1211 1278
+5
include/linux/sunrpc/cache.h
··· 224 224 umode_t, struct cache_detail *); 225 225 extern void sunrpc_cache_unregister_pipefs(struct cache_detail *); 226 226 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 + 227 232 extern void qword_add(char **bpp, int *lp, char *str); 228 233 extern void qword_addhex(char **bpp, int *lp, char *buf, int blen); 229 234 extern int qword_get(char **bpp, char *dest, int bufsize);
+9 -6
net/sunrpc/cache.c
··· 1270 1270 * get a header, then pass each real item in the cache 1271 1271 */ 1272 1272 1273 - static void *c_start(struct seq_file *m, loff_t *pos) 1273 + void *cache_seq_start(struct seq_file *m, loff_t *pos) 1274 1274 __acquires(cd->hash_lock) 1275 1275 { 1276 1276 loff_t n = *pos; ··· 1298 1298 *pos = n+1; 1299 1299 return cd->hash_table[hash]; 1300 1300 } 1301 + EXPORT_SYMBOL_GPL(cache_seq_start); 1301 1302 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) 1303 1304 { 1304 1305 struct cache_head *ch = p; 1305 1306 int hash = (*pos >> 32); ··· 1326 1325 ++*pos; 1327 1326 return cd->hash_table[hash]; 1328 1327 } 1328 + EXPORT_SYMBOL_GPL(cache_seq_next); 1329 1329 1330 - static void c_stop(struct seq_file *m, void *p) 1330 + void cache_seq_stop(struct seq_file *m, void *p) 1331 1331 __releases(cd->hash_lock) 1332 1332 { 1333 1333 struct cache_detail *cd = m->private; 1334 1334 read_unlock(&cd->hash_lock); 1335 1335 } 1336 + EXPORT_SYMBOL_GPL(cache_seq_stop); 1336 1337 1337 1338 static int c_show(struct seq_file *m, void *p) 1338 1339 { ··· 1362 1359 } 1363 1360 1364 1361 static const struct seq_operations cache_content_op = { 1365 - .start = c_start, 1366 - .next = c_next, 1367 - .stop = c_stop, 1362 + .start = cache_seq_start, 1363 + .next = cache_seq_next, 1364 + .stop = cache_seq_stop, 1368 1365 .show = c_show, 1369 1366 }; 1370 1367