Skip to content

Commit ba827c9

Browse files
author
Trond Myklebust
committed
pNFS: Enable per-layout segment commit structures
Enable adding and lookup of per-layout segment commits in filelayout and flexfilelayout. Signed-off-by: Trond Myklebust <[email protected]>
1 parent a990189 commit ba827c9

File tree

4 files changed

+117
-6
lines changed

4 files changed

+117
-6
lines changed

fs/nfs/filelayout/filelayout.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,26 @@ filelayout_get_ds_info(struct inode *inode)
11681168
return &FILELAYOUT_FROM_HDR(layout)->commit_info;
11691169
}
11701170

1171+
static void
1172+
filelayout_setup_ds_info(struct pnfs_ds_commit_info *fl_cinfo,
1173+
struct pnfs_layout_segment *lseg)
1174+
{
1175+
struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
1176+
struct inode *inode = lseg->pls_layout->plh_inode;
1177+
struct pnfs_commit_array *array, *new;
1178+
unsigned int size = (fl->stripe_type == STRIPE_SPARSE) ?
1179+
fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
1180+
1181+
new = pnfs_alloc_commit_array(size, GFP_NOIO);
1182+
if (new) {
1183+
spin_lock(&inode->i_lock);
1184+
array = pnfs_add_commit_array(fl_cinfo, new, lseg);
1185+
spin_unlock(&inode->i_lock);
1186+
if (array != new)
1187+
pnfs_free_commit_array(new);
1188+
}
1189+
}
1190+
11711191
static void
11721192
filelayout_release_ds_info(struct pnfs_ds_commit_info *fl_cinfo,
11731193
struct inode *inode)
@@ -1191,6 +1211,7 @@ static struct pnfs_layoutdriver_type filelayout_type = {
11911211
.pg_read_ops = &filelayout_pg_read_ops,
11921212
.pg_write_ops = &filelayout_pg_write_ops,
11931213
.get_ds_info = &filelayout_get_ds_info,
1214+
.setup_ds_info = filelayout_setup_ds_info,
11941215
.release_ds_info = filelayout_release_ds_info,
11951216
.mark_request_commit = filelayout_mark_request_commit,
11961217
.clear_request_commit = pnfs_generic_clear_request_commit,

fs/nfs/flexfilelayout/flexfilelayout.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,24 @@ ff_layout_get_ds_info(struct inode *inode)
20042004
return &FF_LAYOUT_FROM_HDR(layout)->commit_info;
20052005
}
20062006

2007+
static void
2008+
ff_layout_setup_ds_info(struct pnfs_ds_commit_info *fl_cinfo,
2009+
struct pnfs_layout_segment *lseg)
2010+
{
2011+
struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg);
2012+
struct inode *inode = lseg->pls_layout->plh_inode;
2013+
struct pnfs_commit_array *array, *new;
2014+
2015+
new = pnfs_alloc_commit_array(flseg->mirror_array_cnt, GFP_NOIO);
2016+
if (new) {
2017+
spin_lock(&inode->i_lock);
2018+
array = pnfs_add_commit_array(fl_cinfo, new, lseg);
2019+
spin_unlock(&inode->i_lock);
2020+
if (array != new)
2021+
pnfs_free_commit_array(new);
2022+
}
2023+
}
2024+
20072025
static void
20082026
ff_layout_release_ds_info(struct pnfs_ds_commit_info *fl_cinfo,
20092027
struct inode *inode)
@@ -2513,6 +2531,7 @@ static struct pnfs_layoutdriver_type flexfilelayout_type = {
25132531
.pg_read_ops = &ff_layout_pg_read_ops,
25142532
.pg_write_ops = &ff_layout_pg_write_ops,
25152533
.get_ds_info = ff_layout_get_ds_info,
2534+
.setup_ds_info = ff_layout_setup_ds_info,
25162535
.release_ds_info = ff_layout_release_ds_info,
25172536
.free_deviceid_node = ff_layout_free_deviceid_node,
25182537
.mark_request_commit = pnfs_layout_mark_request_commit,

fs/nfs/pnfs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ struct pnfs_layoutdriver_type {
150150
const struct nfs_pageio_ops *pg_write_ops;
151151

152152
struct pnfs_ds_commit_info *(*get_ds_info) (struct inode *inode);
153+
void (*setup_ds_info)(struct pnfs_ds_commit_info *,
154+
struct pnfs_layout_segment *);
153155
void (*release_ds_info)(struct pnfs_ds_commit_info *,
154156
struct inode *inode);
155157
void (*mark_request_commit) (struct nfs_page *req,
@@ -371,6 +373,10 @@ void nfs4_deviceid_purge_client(const struct nfs_client *);
371373
/* pnfs_nfs.c */
372374
struct pnfs_commit_array *pnfs_alloc_commit_array(size_t n, gfp_t gfp_flags);
373375
void pnfs_free_commit_array(struct pnfs_commit_array *p);
376+
struct pnfs_commit_array *pnfs_add_commit_array(struct pnfs_ds_commit_info *,
377+
struct pnfs_commit_array *,
378+
struct pnfs_layout_segment *);
379+
374380
void pnfs_generic_ds_cinfo_release_lseg(struct pnfs_ds_commit_info *fl_cinfo,
375381
struct pnfs_layout_segment *lseg);
376382
void pnfs_generic_ds_cinfo_destroy(struct pnfs_ds_commit_info *fl_cinfo);

fs/nfs/pnfs_nfs.c

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,66 @@ pnfs_free_commit_array(struct pnfs_commit_array *p)
118118
}
119119
EXPORT_SYMBOL_GPL(pnfs_free_commit_array);
120120

121+
static struct pnfs_commit_array *
122+
pnfs_find_commit_array_by_lseg(struct pnfs_ds_commit_info *fl_cinfo,
123+
struct pnfs_layout_segment *lseg)
124+
{
125+
struct pnfs_commit_array *array;
126+
127+
list_for_each_entry_rcu(array, &fl_cinfo->commits, cinfo_list) {
128+
if (array->lseg == lseg)
129+
return array;
130+
}
131+
return NULL;
132+
}
133+
134+
struct pnfs_commit_array *
135+
pnfs_add_commit_array(struct pnfs_ds_commit_info *fl_cinfo,
136+
struct pnfs_commit_array *new,
137+
struct pnfs_layout_segment *lseg)
138+
{
139+
struct pnfs_commit_array *array;
140+
141+
array = pnfs_find_commit_array_by_lseg(fl_cinfo, lseg);
142+
if (array)
143+
return array;
144+
new->lseg = lseg;
145+
refcount_set(&new->refcount, 1);
146+
list_add_rcu(&new->cinfo_list, &fl_cinfo->commits);
147+
list_add(&new->lseg_list, &lseg->pls_commits);
148+
return new;
149+
}
150+
EXPORT_SYMBOL_GPL(pnfs_add_commit_array);
151+
152+
static void
153+
pnfs_setup_ds_info(struct pnfs_ds_commit_info *fl_cinfo,
154+
struct pnfs_layout_segment *lseg)
155+
{
156+
struct inode *inode = lseg->pls_layout->plh_inode;
157+
struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
158+
159+
if (ld->setup_ds_info != NULL)
160+
ld->setup_ds_info(fl_cinfo, lseg);
161+
}
162+
163+
static struct pnfs_commit_array *
164+
pnfs_lookup_commit_array(struct pnfs_ds_commit_info *fl_cinfo,
165+
struct pnfs_layout_segment *lseg)
166+
{
167+
struct pnfs_commit_array *array;
168+
169+
rcu_read_lock();
170+
array = pnfs_find_commit_array_by_lseg(fl_cinfo, lseg);
171+
if (!array) {
172+
rcu_read_unlock();
173+
pnfs_setup_ds_info(fl_cinfo, lseg);
174+
rcu_read_lock();
175+
array = pnfs_find_commit_array_by_lseg(fl_cinfo, lseg);
176+
}
177+
rcu_read_unlock();
178+
return array;
179+
}
180+
121181
static void
122182
pnfs_release_commit_array_locked(struct pnfs_commit_array *array)
123183
{
@@ -1082,17 +1142,18 @@ pnfs_layout_mark_request_commit(struct nfs_page *req,
10821142
u32 ds_commit_idx)
10831143
{
10841144
struct list_head *list;
1145+
struct pnfs_commit_array *array;
10851146
struct pnfs_commit_bucket *buckets;
10861147

10871148
mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
1088-
buckets = cinfo->ds->buckets;
1149+
array = pnfs_lookup_commit_array(cinfo->ds, lseg);
1150+
if (!array)
1151+
goto out_resched;
1152+
buckets = array->buckets;
10891153
list = &buckets[ds_commit_idx].written;
10901154
if (list_empty(list)) {
1091-
if (!pnfs_is_valid_lseg(lseg)) {
1092-
mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
1093-
cinfo->completion_ops->resched_write(cinfo, req);
1094-
return;
1095-
}
1155+
if (!pnfs_is_valid_lseg(lseg))
1156+
goto out_resched;
10961157
/* Non-empty buckets hold a reference on the lseg. That ref
10971158
* is normally transferred to the COMMIT call and released
10981159
* there. It could also be released if the last req is pulled
@@ -1108,6 +1169,10 @@ pnfs_layout_mark_request_commit(struct nfs_page *req,
11081169
nfs_request_add_commit_list_locked(req, list, cinfo);
11091170
mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
11101171
nfs_mark_page_unstable(req->wb_page, cinfo);
1172+
return;
1173+
out_resched:
1174+
mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
1175+
cinfo->completion_ops->resched_write(cinfo, req);
11111176
}
11121177
EXPORT_SYMBOL_GPL(pnfs_layout_mark_request_commit);
11131178

0 commit comments

Comments
 (0)