At Tue, 14 May 2013 15:25:10 +0800,
Liu Yuan wrote:
> 
> > +
> > +static int set_sha1_cache(uint64_t oid, uint32_t epoch, const uint8_t 
> > *sha1)
> > +{
> > +   char path[PATH_MAX];
> > +
> > +   if (!oid_is_readonly(oid))
> > +           return -1;
> > +
> 
> Stale object isn't marked readonly yet. So your patch won't be useful
> for recovery?

Useful for recovery of snapshot objects only.

> 
> > +   if (default_exist(oid))
> > +           get_obj_path(oid, path);
> > +   else
> > +           get_stale_obj_path(oid, epoch, path);
> > +
> > +   return setxattr(path, SHA1NAME, sha1, SHA1_LEN, 0);
> 
> setxattr can fail, need failure handling.

Okay, but I think we cannot handle the error but only print the error
message.  We can safely ignore the error because sheep can still work
even if we cannot save the cache.

> 
> > +}
> > +
> >  int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1)
> >  {
> >     int ret;
> > @@ -485,6 +527,11 @@ int default_get_hash(uint64_t oid, uint32_t epoch, 
> > uint8_t *sha1)
> >     uint64_t offset = 0;
> >     uint32_t length;
> >  
> > +   if (get_sha1_cache(oid, epoch, sha1) == 0) {
> > +           sd_dprintf("use cached sha1 digest %s", sha1_to_hex(sha1));
> > +           return SD_RES_SUCCESS;
> > +   }
> > +
> >     length = get_objsize(oid);
> >     buf = malloc(length);
> >     if (buf == NULL)
> > @@ -512,6 +559,8 @@ int default_get_hash(uint64_t oid, uint32_t epoch, 
> > uint8_t *sha1)
> >     sd_dprintf("the message digest of %"PRIx64" at epoch %d is %s", oid,
> >                epoch, sha1_to_hex(sha1));
> >  
> > +   set_sha1_cache(oid, epoch, sha1);
> 
> Better name as get/set_object_sha1() and put oid_is_readonly() check in
> the default_get_hash() will make the code better readability.

Agreed.

Thanks,

Kazutaka
-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to