@@ -2853,6 +2853,7 @@ check_clone(int clonenum, bool replay_image)
28532853 struct rbd_ctx cur_ctx = RBD_CTX_INIT;
28542854 struct stat file_info;
28552855 char *good_buf, *temp_buf;
2856+ uint64_t size;
28562857
28572858 if (replay_image) {
28582859 replay_imagename (imagename, sizeof (imagename), clonenum);
@@ -2864,40 +2865,51 @@ check_clone(int clonenum, bool replay_image)
28642865 prterrcode (" check_clone: ops->open" , ret);
28652866 exit (167 );
28662867 }
2868+ if ((ret = ops->get_size (&cur_ctx, &size)) < 0 ) {
2869+ prterrcode (" check_clone: ops->get_size" , ret);
2870+ exit (167 );
2871+ }
28672872
28682873 clone_filename (filename, sizeof (filename), clonenum + 1 );
28692874 if ((fd = open (filename, O_RDONLY | O_BINARY)) < 0 ) {
2870- simple_err (" check_clone: open" , -errno);
2875+ prterrcode (" check_clone: open" , -errno);
28712876 exit (168 );
28722877 }
2878+ if (fstat (fd, &file_info) < 0 ) {
2879+ prterrcode (" check_clone: fstat" , -errno);
2880+ exit (169 );
2881+ }
28732882
28742883 prt (" checking clone #%d, image %s against file %s\n " ,
28752884 clonenum, imagename, filename);
2876- if ((ret = fstat (fd, &file_info)) < 0 ) {
2877- simple_err (" check_clone: fstat" , -errno);
2878- exit (169 );
2885+ if (size != (uint64_t )file_info.st_size ) {
2886+ prt (" check_clone: image size 0x%llx != file size 0x%llx\n " ,
2887+ (unsigned long long )size,
2888+ (unsigned long long )file_info.st_size );
2889+ exit (175 );
28792890 }
28802891
28812892 good_buf = NULL ;
2882- ret = posix_memalign ((void **)&good_buf,
2883- std::max (writebdy, (int )sizeof (void *)),
2884- file_info.st_size );
2885- if (ret > 0 ) {
2886- prterrcode (" check_clone: posix_memalign(good_buf)" , -ret);
2887- exit (96 );
2888- }
2889-
28902893 temp_buf = NULL ;
2891- ret = posix_memalign ((void **)&temp_buf,
2892- std::max (readbdy, (int )sizeof (void *)),
2893- file_info.st_size );
2894- if (ret > 0 ) {
2895- prterrcode (" check_clone: posix_memalign(temp_buf)" , -ret);
2896- exit (97 );
2894+ if (file_info.st_size > 0 ) {
2895+ ret = posix_memalign ((void **)&good_buf,
2896+ std::max (writebdy, (int )sizeof (void *)),
2897+ file_info.st_size );
2898+ if (ret > 0 ) {
2899+ prterrcode (" check_clone: posix_memalign(good_buf)" , -ret);
2900+ exit (96 );
2901+ }
2902+ ret = posix_memalign ((void **)&temp_buf,
2903+ std::max (readbdy, (int )sizeof (void *)),
2904+ file_info.st_size );
2905+ if (ret > 0 ) {
2906+ prterrcode (" check_clone: posix_memalign(temp_buf)" , -ret);
2907+ exit (97 );
2908+ }
28972909 }
28982910
2899- if ((ret = pread (fd, good_buf, file_info.st_size , 0 ) ) < 0 ) {
2900- simple_err (" check_clone: pread" , -errno);
2911+ if (pread (fd, good_buf, file_info.st_size , 0 ) < 0 ) {
2912+ prterrcode (" check_clone: pread" , -errno);
29012913 exit (170 );
29022914 }
29032915 if ((ret = ops->read (&cur_ctx, 0 , file_info.st_size , temp_buf)) < 0 ) {
0 commit comments