CacheFiles: Implement interface to check cache consistency
[firefly-linux-kernel-4.4.55.git] / fs / cachefiles / xattr.c
index 2476e5162609ffc4db6be49549e27999e288f06f..34c88b83e39f1214b0ed7f2c22bc58f5acd00fa4 100644 (file)
@@ -156,6 +156,42 @@ int cachefiles_update_object_xattr(struct cachefiles_object *object,
        return ret;
 }
 
+/*
+ * check the consistency between the backing cache and the FS-Cache cookie
+ */
+int cachefiles_check_auxdata(struct cachefiles_object *object)
+{
+       struct cachefiles_xattr *auxbuf;
+       struct dentry *dentry = object->dentry;
+       unsigned int dlen;
+       int ret;
+
+       ASSERT(dentry);
+       ASSERT(dentry->d_inode);
+       ASSERT(object->fscache.cookie->def->check_aux);
+
+       auxbuf = kmalloc(sizeof(struct cachefiles_xattr) + 512, GFP_KERNEL);
+       if (!auxbuf)
+               return -ENOMEM;
+
+       auxbuf->len = vfs_getxattr(dentry, cachefiles_xattr_cache,
+                                  &auxbuf->type, 512 + 1);
+       if (auxbuf->len < 1)
+               return -ESTALE;
+
+       if (auxbuf->type != object->fscache.cookie->def->type)
+               return -ESTALE;
+
+       dlen = auxbuf->len - 1;
+       ret = fscache_check_aux(&object->fscache, &auxbuf->data, dlen);
+
+       kfree(auxbuf);
+       if (ret != FSCACHE_CHECKAUX_OKAY)
+               return -ESTALE;
+
+       return 0;
+}
+
 /*
  * check the state xattr on a cache file
  * - return -ESTALE if the object should be deleted