@@ -68,6 +68,7 @@ struct netfs_inode {
6868 loff_t remote_i_size ; /* Size of the remote file */
6969 loff_t zero_point ; /* Size after which we assume there's no data
7070 * on the server */
71+ atomic_t io_count ; /* Number of outstanding reqs */
7172 unsigned long flags ;
7273#define NETFS_ICTX_ODIRECT 0 /* The file has DIO in progress */
7374#define NETFS_ICTX_UNBUFFERED 1 /* I/O should not use the pagecache */
@@ -472,6 +473,7 @@ static inline void netfs_inode_init(struct netfs_inode *ctx,
472473 ctx -> remote_i_size = i_size_read (& ctx -> inode );
473474 ctx -> zero_point = LLONG_MAX ;
474475 ctx -> flags = 0 ;
476+ atomic_set (& ctx -> io_count , 0 );
475477#if IS_ENABLED (CONFIG_FSCACHE )
476478 ctx -> cache = NULL ;
477479#endif
@@ -515,4 +517,20 @@ static inline struct fscache_cookie *netfs_i_cookie(struct netfs_inode *ctx)
515517#endif
516518}
517519
520+ /**
521+ * netfs_wait_for_outstanding_io - Wait for outstanding I/O to complete
522+ * @ctx: The netfs inode to wait on
523+ *
524+ * Wait for outstanding I/O requests of any type to complete. This is intended
525+ * to be called from inode eviction routines. This makes sure that any
526+ * resources held by those requests are cleaned up before we let the inode get
527+ * cleaned up.
528+ */
529+ static inline void netfs_wait_for_outstanding_io (struct inode * inode )
530+ {
531+ struct netfs_inode * ictx = netfs_inode (inode );
532+
533+ wait_var_event (& ictx -> io_count , atomic_read (& ictx -> io_count ) == 0 );
534+ }
535+
518536#endif /* _LINUX_NETFS_H */
0 commit comments