From: Patrick Farrell Date: Wed, 24 Jul 2019 19:50:23 +0000 (-0400) Subject: LU-12586 lov: Correct write_intent end for trunc X-Git-Tag: 2.12.3-RC1~88 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F35836%2F2;p=fs%2Flustre-release.git LU-12586 lov: Correct write_intent end for trunc When instantiating a layout, the server interprets the write intent from the client as the range [start, end), not including the last byte. This is correct for writes because the last byte given for a write is actually 'endpos', the resulting file pointer position, and so is not included. However, truncate is specifiying a size, not an endpos, so truncate is [start, size]. To make this work with the [start, end) processing for write_intents, we have to add 1 to the size when sending a write intent. Without this, a truncate operation to the first byte of a new layout component fails silently because the component is not instantiated. Lustre-change: https://review.whamcloud.com/35607 Lustre-commit: c32c7401426d46b371fa993bba17265443fefa1b Signed-off-by: Patrick Farrell Change-Id: Id2b07abe73455bf1f0ed841ad08c5f381a871315 Reviewed-by: Andreas Dilger Reviewed-by: Mike Pershin Signed-off-by: Minh Diep Reviewed-on: https://review.whamcloud.com/35836 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/lov/lov_io.c b/lustre/lov/lov_io.c index 5ec45bd..3a1ea0f 100644 --- a/lustre/lov/lov_io.c +++ b/lustre/lov/lov_io.c @@ -563,7 +563,15 @@ static int lov_io_slice_init(struct lov_io *lio, */ if (cl_io_is_trunc(io)) { io->ci_write_intent.e_start = 0; - io->ci_write_intent.e_end = io->u.ci_setattr.sa_attr.lvb_size; + /* for writes, e_end is endpos, the location of the file + * pointer after the write is completed, so it is not accessed. + * For truncate, 'end' is the size, and *is* acccessed. + * In other words, writes are [start, end), but truncate is + * [start, size], where both are included. So add 1 to the + * size when creating the write intent to account for this. + */ + io->ci_write_intent.e_end = + io->u.ci_setattr.sa_attr.lvb_size + 1; } else { io->ci_write_intent.e_start = lio->lis_pos; io->ci_write_intent.e_end = lio->lis_endpos; diff --git a/lustre/tests/sanity-pfl.sh b/lustre/tests/sanity-pfl.sh index f7ca7ef..a340dab 100644 --- a/lustre/tests/sanity-pfl.sh +++ b/lustre/tests/sanity-pfl.sh @@ -440,7 +440,8 @@ test_11() { [[ -n $f4 ]] && error "1: 4th component instantiated" # the first 2 components instantiated - $TRUNCATE $comp_file $((1024*1024*1+1)) + # Truncate to exact start of new component - LU-12586 + $TRUNCATE $comp_file $((1024*1024*1)) f2=$($LFS getstripe -I2 $comp_file | grep "l_fid") [[ -z $f2 ]] && error "2: 2nd component uninstantiated" @@ -450,7 +451,7 @@ test_11() { [[ -n $f4 ]] && error "2: 4th component instantiated" # the first 3 components instantiated - $TRUNCATE $comp_file $((1024*1024*3)) + $TRUNCATE $comp_file $((1024*1024*3 - 1)) $TRUNCATE $comp_file $((1024*1024*1+1)) f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")