]> git.ipfire.org Git - thirdparty/kernel/linux.git/blobdiff - fs/cachefiles/internal.h
Merge tag 'vfs-6.8.netfs' of gitolite.kernel.org:pub/scm/linux/kernel/git/vfs/vfs
[thirdparty/kernel/linux.git] / fs / cachefiles / internal.h
index 1af48d576a34d6e1e1f9f9919ecea746d7ae4ac8..d33169f0018b103a7ad30ed20b258869e740e556 100644 (file)
@@ -44,6 +44,19 @@ struct cachefiles_volume {
        struct dentry                   *fanout[256];   /* Fanout subdirs */
 };
 
+enum cachefiles_object_state {
+       CACHEFILES_ONDEMAND_OBJSTATE_CLOSE, /* Anonymous fd closed by daemon or initial state */
+       CACHEFILES_ONDEMAND_OBJSTATE_OPEN, /* Anonymous fd associated with object is available */
+       CACHEFILES_ONDEMAND_OBJSTATE_REOPENING, /* Object that was closed and is being reopened. */
+};
+
+struct cachefiles_ondemand_info {
+       struct work_struct              ondemand_work;
+       int                             ondemand_id;
+       enum cachefiles_object_state    state;
+       struct cachefiles_object        *object;
+};
+
 /*
  * Backing file state.
  */
@@ -61,7 +74,7 @@ struct cachefiles_object {
        unsigned long                   flags;
 #define CACHEFILES_OBJECT_USING_TMPFILE        0               /* Have an unlinked tmpfile */
 #ifdef CONFIG_CACHEFILES_ONDEMAND
-       int                             ondemand_id;
+       struct cachefiles_ondemand_info *ondemand;
 #endif
 };
 
@@ -290,12 +303,42 @@ extern ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
 extern int cachefiles_ondemand_copen(struct cachefiles_cache *cache,
                                     char *args);
 
+extern int cachefiles_ondemand_restore(struct cachefiles_cache *cache,
+                                       char *args);
+
 extern int cachefiles_ondemand_init_object(struct cachefiles_object *object);
 extern void cachefiles_ondemand_clean_object(struct cachefiles_object *object);
 
 extern int cachefiles_ondemand_read(struct cachefiles_object *object,
                                    loff_t pos, size_t len);
 
+extern int cachefiles_ondemand_init_obj_info(struct cachefiles_object *obj,
+                                       struct cachefiles_volume *volume);
+extern void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *obj);
+
+#define CACHEFILES_OBJECT_STATE_FUNCS(_state, _STATE)  \
+static inline bool                                                             \
+cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *object) \
+{                                                                                              \
+       return object->ondemand->state == CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \
+}                                                                                              \
+                                                                                               \
+static inline void                                                             \
+cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \
+{                                                                                              \
+       object->ondemand->state = CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \
+}
+
+CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN);
+CACHEFILES_OBJECT_STATE_FUNCS(close, CLOSE);
+CACHEFILES_OBJECT_STATE_FUNCS(reopening, REOPENING);
+
+static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req)
+{
+       return cachefiles_ondemand_object_is_reopening(req->object) &&
+                       req->msg.opcode == CACHEFILES_OP_READ;
+}
+
 #else
 static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
                                        char __user *_buffer, size_t buflen)
@@ -317,6 +360,20 @@ static inline int cachefiles_ondemand_read(struct cachefiles_object *object,
 {
        return -EOPNOTSUPP;
 }
+
+static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *obj,
+                                               struct cachefiles_volume *volume)
+{
+       return 0;
+}
+static inline void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *obj)
+{
+}
+
+static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req)
+{
+       return false;
+}
 #endif
 
 /*