Skip to content

Commit b3dce6a

Browse files
bcodding-rhtrondmypd
authored andcommitted
pnfs/blocklayout: handle transient devices
PNFS block/SCSI layouts should gracefully handle cases where block devices are not available when a layout is retrieved, or the block devices are removed while the client holds a layout. While setting up a layout segment, keep a record of an unavailable or un-parsable block device in cache with a flag so that subsequent layouts do not spam the server with GETDEVINFO. We can reuse the current NFS_DEVICEID_UNAVAILABLE handling with one variation: instead of reusing the device, we will discard it and send a fresh GETDEVINFO after the timeout, since the lookup and validation of the device occurs within the GETDEVINFO response handling. A lookup of a layout segment that references an unavailable device will return a segment with the NFS_LSEG_UNAVAILABLE flag set. This will allow the pgio layer to mark the layout with the appropriate fail bit, which forces subsequent IO to the MDS, and prevents spamming the server with LAYOUTGET, LAYOUTRETURN. Finally, when IO to a block device fails, look up the block device(s) referenced by the pgio header, and mark them as unavailable. Signed-off-by: Benjamin Coddington <bcodding@redhat.com> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent d78471d commit b3dce6a

5 files changed

Lines changed: 82 additions & 12 deletions

File tree

‎fs/nfs/blocklayout/blocklayout.c‎

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,29 @@ do_add_page_to_bio(struct bio *bio, int npg, int rw, sector_t isect,
184184
return bio;
185185
}
186186

187+
static void bl_mark_devices_unavailable(struct nfs_pgio_header *header, bool rw)
188+
{
189+
struct pnfs_block_layout *bl = BLK_LSEG2EXT(header->lseg);
190+
size_t bytes_left = header->args.count;
191+
sector_t isect, extent_length = 0;
192+
struct pnfs_block_extent be;
193+
194+
isect = header->args.offset >> SECTOR_SHIFT;
195+
bytes_left += header->args.offset - (isect << SECTOR_SHIFT);
196+
197+
while (bytes_left > 0) {
198+
if (!ext_tree_lookup(bl, isect, &be, rw))
199+
return;
200+
extent_length = be.be_length - (isect - be.be_f_offset);
201+
nfs4_mark_deviceid_unavailable(be.be_device);
202+
isect += extent_length;
203+
if (bytes_left > extent_length << SECTOR_SHIFT)
204+
bytes_left -= extent_length << SECTOR_SHIFT;
205+
else
206+
bytes_left = 0;
207+
}
208+
}
209+
187210
static void bl_end_io_read(struct bio *bio)
188211
{
189212
struct parallel_io *par = bio->bi_private;
@@ -194,6 +217,7 @@ static void bl_end_io_read(struct bio *bio)
194217
if (!header->pnfs_error)
195218
header->pnfs_error = -EIO;
196219
pnfs_set_lo_fail(header->lseg);
220+
bl_mark_devices_unavailable(header, false);
197221
}
198222

199223
bio_put(bio);
@@ -323,6 +347,7 @@ static void bl_end_io_write(struct bio *bio)
323347
if (!header->pnfs_error)
324348
header->pnfs_error = -EIO;
325349
pnfs_set_lo_fail(header->lseg);
350+
bl_mark_devices_unavailable(header, true);
326351
}
327352
bio_put(bio);
328353
put_parallel(par);
@@ -552,6 +577,31 @@ static int decode_sector_number(__be32 **rp, sector_t *sp)
552577
return 0;
553578
}
554579

580+
static struct nfs4_deviceid_node *
581+
bl_find_get_deviceid(struct nfs_server *server,
582+
const struct nfs4_deviceid *id, struct rpc_cred *cred,
583+
gfp_t gfp_mask)
584+
{
585+
struct nfs4_deviceid_node *node;
586+
unsigned long start, end;
587+
588+
retry:
589+
node = nfs4_find_get_deviceid(server, id, cred, gfp_mask);
590+
if (!node)
591+
return ERR_PTR(-ENODEV);
592+
593+
if (test_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags) == 0)
594+
return node;
595+
596+
end = jiffies;
597+
start = end - PNFS_DEVICE_RETRY_TIMEOUT;
598+
if (!time_in_range(node->timestamp_unavailable, start, end)) {
599+
nfs4_delete_deviceid(node->ld, node->nfs_client, id);
600+
goto retry;
601+
}
602+
return ERR_PTR(-ENODEV);
603+
}
604+
555605
static int
556606
bl_alloc_extent(struct xdr_stream *xdr, struct pnfs_layout_hdr *lo,
557607
struct layout_verification *lv, struct list_head *extents,
@@ -573,16 +623,18 @@ bl_alloc_extent(struct xdr_stream *xdr, struct pnfs_layout_hdr *lo,
573623
memcpy(&id, p, NFS4_DEVICEID4_SIZE);
574624
p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE);
575625

576-
error = -EIO;
577-
be->be_device = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode), &id,
626+
be->be_device = bl_find_get_deviceid(NFS_SERVER(lo->plh_inode), &id,
578627
lo->plh_lc_cred, gfp_mask);
579-
if (!be->be_device)
628+
if (IS_ERR(be->be_device)) {
629+
error = PTR_ERR(be->be_device);
580630
goto out_free_be;
631+
}
581632

582633
/*
583634
* The next three values are read in as bytes, but stored in the
584635
* extent structure in 512-byte granularity.
585636
*/
637+
error = -EIO;
586638
if (decode_sector_number(&p, &be->be_f_offset) < 0)
587639
goto out_put_deviceid;
588640
if (decode_sector_number(&p, &be->be_length) < 0)
@@ -692,11 +744,16 @@ bl_alloc_lseg(struct pnfs_layout_hdr *lo, struct nfs4_layoutget_res *lgr,
692744
__free_page(scratch);
693745
out:
694746
dprintk("%s returns %d\n", __func__, status);
695-
if (status) {
747+
switch (status) {
748+
case -ENODEV:
749+
/* Our extent block devices are unavailable */
750+
set_bit(NFS_LSEG_UNAVAILABLE, &lseg->pls_flags);
751+
case 0:
752+
return lseg;
753+
default:
696754
kfree(lseg);
697755
return ERR_PTR(status);
698756
}
699-
return lseg;
700757
}
701758

702759
static void
@@ -798,6 +855,13 @@ bl_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
798855
}
799856

800857
pnfs_generic_pg_init_read(pgio, req);
858+
859+
if (pgio->pg_lseg &&
860+
test_bit(NFS_LSEG_UNAVAILABLE, &pgio->pg_lseg->pls_flags)) {
861+
pnfs_error_mark_layout_for_return(pgio->pg_inode, pgio->pg_lseg);
862+
pnfs_set_lo_fail(pgio->pg_lseg);
863+
nfs_pageio_reset_read_mds(pgio);
864+
}
801865
}
802866

803867
/*
@@ -853,6 +917,14 @@ bl_pg_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
853917
wb_size = nfs_dreq_bytes_left(pgio->pg_dreq);
854918

855919
pnfs_generic_pg_init_write(pgio, req, wb_size);
920+
921+
if (pgio->pg_lseg &&
922+
test_bit(NFS_LSEG_UNAVAILABLE, &pgio->pg_lseg->pls_flags)) {
923+
924+
pnfs_error_mark_layout_for_return(pgio->pg_inode, pgio->pg_lseg);
925+
pnfs_set_lo_fail(pgio->pg_lseg);
926+
nfs_pageio_reset_write_mds(pgio);
927+
}
856928
}
857929

858930
/*

‎fs/nfs/blocklayout/dev.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,14 +533,11 @@ bl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
533533
goto out_free_volumes;
534534

535535
ret = bl_parse_deviceid(server, top, volumes, nr_volumes - 1, gfp_mask);
536-
if (ret) {
537-
bl_free_device(top);
538-
kfree(top);
539-
goto out_free_volumes;
540-
}
541536

542537
node = &top->node;
543538
nfs4_init_deviceid_node(node, server, &pdev->dev_id);
539+
if (ret)
540+
nfs4_mark_deviceid_unavailable(node);
544541

545542
out_free_volumes:
546543
kfree(volumes);

‎fs/nfs/pnfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ pnfs_mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo,
655655
return 0;
656656
list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list)
657657
if (pnfs_match_lseg_recall(lseg, recall_range, seq)) {
658-
dprintk("%s: freeing lseg %p iomode %d seq %u"
658+
dprintk("%s: freeing lseg %p iomode %d seq %u "
659659
"offset %llu length %llu\n", __func__,
660660
lseg, lseg->pls_range.iomode, lseg->pls_seq,
661661
lseg->pls_range.offset, lseg->pls_range.length);

‎fs/nfs/pnfs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ enum {
4040
NFS_LSEG_ROC, /* roc bit received from server */
4141
NFS_LSEG_LAYOUTCOMMIT, /* layoutcommit bit set for layoutcommit */
4242
NFS_LSEG_LAYOUTRETURN, /* layoutreturn bit set for layoutreturn */
43+
NFS_LSEG_UNAVAILABLE, /* unavailable bit set for temporary problem */
4344
};
4445

4546
/* Individual ip address */
@@ -86,6 +87,7 @@ enum pnfs_try_status {
8687
*/
8788
#define NFS4_DEF_DS_TIMEO 600 /* in tenths of a second */
8889
#define NFS4_DEF_DS_RETRANS 5
90+
#define PNFS_DEVICE_RETRY_TIMEOUT (120*HZ)
8991

9092
/* error codes for internal use */
9193
#define NFS4ERR_RESET_TO_MDS 12001

‎fs/nfs/pnfs_dev.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#define NFS4_DEVICE_ID_HASH_SIZE (1 << NFS4_DEVICE_ID_HASH_BITS)
4444
#define NFS4_DEVICE_ID_HASH_MASK (NFS4_DEVICE_ID_HASH_SIZE - 1)
4545

46-
#define PNFS_DEVICE_RETRY_TIMEOUT (120*HZ)
4746

4847
static struct hlist_head nfs4_deviceid_cache[NFS4_DEVICE_ID_HASH_SIZE];
4948
static DEFINE_SPINLOCK(nfs4_deviceid_lock);

0 commit comments

Comments
 (0)