fsnotify: create helpers to get sb and connp from object
authorAmir Goldstein <amir73il@gmail.com>
Sun, 17 Mar 2024 18:41:46 +0000 (20:41 +0200)
committerJan Kara <jack@suse.cz>
Thu, 4 Apr 2024 14:23:46 +0000 (16:23 +0200)
In preparation to passing an object pointer to add/remove/find mark
helpers, create helpers to get sb and connp by object type.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Message-Id: <20240317184154.1200192-3-amir73il@gmail.com>

fs/notify/fsnotify.h
fs/notify/mark.c

index fde74eb333cc93b9b6e7da341e3d79e0a76bc8b9..6d9951aac449cb31ba4eed67cdcb665ba7bb289d 100644 (file)
@@ -27,6 +27,21 @@ static inline struct super_block *fsnotify_conn_sb(
        return container_of(conn->obj, struct super_block, s_fsnotify_marks);
 }
 
+static inline struct super_block *fsnotify_object_sb(void *obj,
+                       enum fsnotify_obj_type obj_type)
+{
+       switch (obj_type) {
+       case FSNOTIFY_OBJ_TYPE_INODE:
+               return ((struct inode *)obj)->i_sb;
+       case FSNOTIFY_OBJ_TYPE_VFSMOUNT:
+               return ((struct vfsmount *)obj)->mnt_sb;
+       case FSNOTIFY_OBJ_TYPE_SB:
+               return (struct super_block *)obj;
+       default:
+               return NULL;
+       }
+}
+
 static inline struct super_block *fsnotify_connector_sb(
                                struct fsnotify_mark_connector *conn)
 {
index 3bcce2671bd54f99ba5d27d87cdb67b0b1c0962c..d9977af258327437f456d2804acd8199a4898a6e 100644 (file)
@@ -97,6 +97,21 @@ void fsnotify_get_mark(struct fsnotify_mark *mark)
        refcount_inc(&mark->refcnt);
 }
 
+static fsnotify_connp_t *fsnotify_object_connp(void *obj,
+                               enum fsnotify_obj_type obj_type)
+{
+       switch (obj_type) {
+       case FSNOTIFY_OBJ_TYPE_INODE:
+               return &((struct inode *)obj)->i_fsnotify_marks;
+       case FSNOTIFY_OBJ_TYPE_VFSMOUNT:
+               return &real_mount(obj)->mnt_fsnotify_marks;
+       case FSNOTIFY_OBJ_TYPE_SB:
+               return &((struct super_block *)obj)->s_fsnotify_marks;
+       default:
+               return NULL;
+       }
+}
+
 static __u32 *fsnotify_conn_mask_p(struct fsnotify_mark_connector *conn)
 {
        if (conn->type == FSNOTIFY_OBJ_TYPE_INODE)