@@ -821,7 +821,7 @@ void get_omap_batch(ObjectMap::ObjectMapIterator &iter, map<string, bufferlist>
821821 }
822822}
823823
824- int ObjectStoreTool::export_file (ObjectStore *store, coll_t cid, ghobject_t &obj)
824+ int ObjectStoreTool::export_file (ObjectStore *store, coll_t cid, ghobject_t &obj, bool force )
825825{
826826 struct stat st;
827827 mysize_t total;
@@ -845,13 +845,19 @@ int ObjectStoreTool::export_file(ObjectStore *store, coll_t cid, ghobject_t &obj
845845 bufferlist bl;
846846 ret = store->getattr (ch, obj, OI_ATTR, bp);
847847 if (ret < 0 ) {
848- cerr << " getattr failure object_info " << ret << std::endl;
849- return ret;
848+ cerr << " getattr failure: " << cpp_strerror (ret)
849+ << " at obj:" << obj
850+ << (force ? " IGNORED" : " " )
851+ << std::endl;
852+ if (!force) {
853+ return ret;
854+ }
855+ } else {
856+ bl.push_back (bp);
857+ decode (objb.oi , bl);
858+ if (debug)
859+ cerr << " object_info: " << objb.oi << std::endl;
850860 }
851- bl.push_back (bp);
852- decode (objb.oi , bl);
853- if (debug)
854- cerr << " object_info: " << objb.oi << std::endl;
855861 }
856862
857863 // NOTE: we include whiteouts, lost, etc.
@@ -869,10 +875,35 @@ int ObjectStoreTool::export_file(ObjectStore *store, coll_t cid, ghobject_t &obj
869875 len = total;
870876
871877 ret = store->read (ch, obj, offset, len, rawdatabl);
872- if (ret < 0 )
873- return ret;
874- if (ret == 0 )
875- return -EINVAL;
878+
879+ ret = ret == 0 ? -EINVAL : ret;
880+ if (ret < 0 ) {
881+ if (!force) {
882+ cerr << " read failure: " << cpp_strerror (ret)
883+ << " at obj:" << obj
884+ << std::hex << " , read 0x" << offset << " ~" << len << std::dec
885+ << std::endl;
886+ return ret;
887+ }
888+ // re-read using minimal disk block to minimize error footprint.
889+ auto o = offset;
890+ const size_t block_size = 4096 ;
891+ while (o < offset + len) {
892+ bufferlist bl;
893+ int r = store->read (ch, obj, o, block_size, bl);
894+ if (r <= 0 ) {
895+ rawdatabl.append_zero (block_size);
896+ cerr << " read failure: " << cpp_strerror (r == 0 ? -EINVAL : r)
897+ << " at obj:" << obj << std::hex
898+ << " , read 0x" << o << " ~" << block_size
899+ << std::dec << std::endl;
900+ } else {
901+ rawdatabl.claim_append (bl);
902+ }
903+ o += block_size;
904+ }
905+ ret = len;
906+ }
876907
877908 data_section dblock (offset, len, rawdatabl);
878909 if (debug)
@@ -941,7 +972,7 @@ int ObjectStoreTool::export_file(ObjectStore *store, coll_t cid, ghobject_t &obj
941972 return 0 ;
942973}
943974
944- int ObjectStoreTool::export_files (ObjectStore *store, coll_t coll)
975+ int ObjectStoreTool::export_files (ObjectStore *store, coll_t coll, bool force )
945976{
946977 ghobject_t next;
947978 auto ch = store->open_collection (coll);
@@ -958,7 +989,7 @@ int ObjectStoreTool::export_files(ObjectStore *store, coll_t coll)
958989 if (i->is_pgmeta () || i->hobj .is_temp () || !i->is_no_gen ()) {
959990 continue ;
960991 }
961- r = export_file (store, coll, *i);
992+ r = export_file (store, coll, *i, force );
962993 if (r < 0 )
963994 return r;
964995 }
@@ -1124,9 +1155,9 @@ int ObjectStoreTool::do_export(
11241155 if (ret)
11251156 return ret;
11261157
1127- ret = export_files (fs, coll);
1158+ ret = export_files (fs, coll, force );
11281159 if (ret) {
1129- cerr << " export_files error " << ret << std::endl;
1160+ cerr << " export_files error: " << cpp_strerror ( ret) << std::endl;
11301161 return ret;
11311162 }
11321163
0 commit comments