int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
- if (!lsm_has_objects(lsm))
- GOTO(out, rc = 0);
+ if (!lsm_has_objects(lsm)) {
+ if (lsm && lsm_is_released(lsm) && (fm_key->fiemap.fm_start <
+ fm_key->oa.o_size)) {
+ /* released file, return a minimal FIEMAP if
+ * request fits in file-size.
+ */
+ fiemap->fm_mapped_extents = 1;
+ fiemap->fm_extents[0].fe_logical =
+ fm_key->fiemap.fm_start;
+ if (fm_key->fiemap.fm_start + fm_key->fiemap.fm_length <
+ fm_key->oa.o_size)
+ fiemap->fm_extents[0].fe_length =
+ fm_key->fiemap.fm_length;
+ else
+ fiemap->fm_extents[0].fe_length =
+ fm_key->oa.o_size -
+ fm_key->fiemap.fm_start;
+ fiemap->fm_extents[0].fe_flags |=
+ (FIEMAP_EXTENT_UNKNOWN |
+ FIEMAP_EXTENT_LAST);
+ }
+ GOTO(out, rc = 0);
+ }
if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
fiemap->fm_mapped_extents = current_extent;
out:
- OBD_FREE_LARGE(fm_local, buffer_size);
+ if (fm_local)
+ OBD_FREE_LARGE(fm_local, buffer_size);
return rc;
}
}
run_test 227 "changelog when explicit setting of HSM flags"
+test_228() {
+ # test needs a running copytool
+ copytool_setup
+
+ dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 conv=sync ||
+ error "creating $DIR/$tfile"
+ $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
+ wait_request_state $(path2fid $DIR/$tfile) ARCHIVE SUCCEED
+
+ $LFS hsm_release $DIR/$tfile
+ check_hsm_flags $DIR/$tfile "0x0000000d"
+
+ filefrag $DIR/$tfile | grep " 1 extent found" ||
+ error "filefrag on released file must return only one extent"
+
+ # only newer versions of cp detect sparse files by stat/FIEMAP
+ # (LU-2580)
+ cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
+ error "copying $DIR/$tfile"
+ cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
+
+ $LFS hsm_release $DIR/$tfile
+ check_hsm_flags $DIR/$tfile "0x0000000d"
+
+ mkdir $DIR/$tdir
+
+ tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
+ error "tar failed"
+ cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
+ error "comparing untarred $DIR/$tfile"
+
+ copytool_cleanup
+}
+run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
+
test_250() {
# test needs a running copytool
copytool_setup