From b5485d307568af92e1a940fa4a7859e6db5b7a97 Mon Sep 17 00:00:00 2001 From: Li Wei Date: Wed, 24 Sep 2014 12:12:37 +0800 Subject: [PATCH] LU-5654 osd-ldiskfs: Handle holes in osd_ldiskfs_read() Current osd_ldiskfs_read() incorrectly returns zero and leaves the corresponding portion of the buffer untouched when a block to be read is not allocated. Change-Id: Idfd441656b99aa039a6bb4f7141b5407553855da Signed-off-by: Li Wei Reviewed-on: http://review.whamcloud.com/12035 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Liang Zhen Reviewed-by: Johann Lombardi Reviewed-by: Oleg Drokin --- lustre/osd-ldiskfs/osd_io.c | 22 ++++++++++++++-------- lustre/tests/conf-sanity.sh | 15 ++++++++++----- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lustre/osd-ldiskfs/osd_io.c b/lustre/osd-ldiskfs/osd_io.c index 9765595..8344d4a 100644 --- a/lustre/osd-ldiskfs/osd_io.c +++ b/lustre/osd-ldiskfs/osd_io.c @@ -1355,15 +1355,21 @@ int osd_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs) boffs = *offs & (blocksize - 1); csize = min(blocksize - boffs, size); bh = ldiskfs_bread(NULL, inode, block, 0, &err); - if (!bh) { - CERROR("%s: can't read %u@%llu on ino %lu: rc = %d\n", - LDISKFS_SB(inode->i_sb)->s_es->s_volume_name, - csize, *offs, inode->i_ino, err); - return err; - } + if (err != 0) { + CERROR("%s: can't read %u@%llu on ino %lu: rc = %d\n", + LDISKFS_SB(inode->i_sb)->s_es->s_volume_name, + csize, *offs, inode->i_ino, err); + if (bh != NULL) + brelse(bh); + return err; + } - memcpy(buf, bh->b_data + boffs, csize); - brelse(bh); + if (bh != NULL) { + memcpy(buf, bh->b_data + boffs, csize); + brelse(bh); + } else { + memset(buf, 0, csize); + } *offs += csize; buf += csize; diff --git a/lustre/tests/conf-sanity.sh b/lustre/tests/conf-sanity.sh index edaf102..b050725 100644 --- a/lustre/tests/conf-sanity.sh +++ b/lustre/tests/conf-sanity.sh @@ -3669,6 +3669,7 @@ run_test 55 "check lov_objid size" test_56() { local mds_journal_size_orig=$MDSJOURNALSIZE + local n MDSJOURNALSIZE=16 @@ -3676,22 +3677,26 @@ test_56() { add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \ --reformat $(mdsdevname $num) $(mdsvdevname $num) done - add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=1000 --reformat \ + add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=10000 --reformat \ $(ostdevname 1) $(ostvdevname 1) - add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=10000 --reformat \ + add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=1000 --reformat \ $(ostdevname 2) $(ostvdevname 2) start_mgsmds - start_ost - start_ost2 || error "Unable to start second ost" + start_ost || error "Unable to start first ost (idx 10000)" + start_ost2 || error "Unable to start second ost (idx 1000)" mount_client $MOUNT || error "Unable to mount client" echo ok $LFS osts + $LFS setstripe --stripe-count=-1 $DIR/$tfile || error "Unable to create" + n=$($LFS getstripe --stripe-count $DIR/$tfile) + [ "$n" -eq 2 ] || error "Stripe count not two: $n" + rm $DIR/$tfile stopall MDSJOURNALSIZE=$mds_journal_size_orig reformat } -run_test 56 "check big indexes" +run_test 56 "check big OST indexes and out-of-index-order start" test_57a() { # bug 22656 local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}') -- 1.8.3.1