cached_dir.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Functions to handle the cached directory entries
  4. *
  5. * Copyright (c) 2022, Ronnie Sahlberg <[email protected]>
  6. */
  7. #ifndef _CACHED_DIR_H
  8. #define _CACHED_DIR_H
  9. struct cached_dirent {
  10. struct list_head entry;
  11. char *name;
  12. int namelen;
  13. loff_t pos;
  14. struct cifs_fattr fattr;
  15. };
  16. struct cached_dirents {
  17. bool is_valid:1;
  18. bool is_failed:1;
  19. struct dir_context *ctx; /*
  20. * Only used to make sure we only take entries
  21. * from a single context. Never dereferenced.
  22. */
  23. struct mutex de_mutex;
  24. int pos; /* Expected ctx->pos */
  25. struct list_head entries;
  26. };
  27. struct cached_fid {
  28. struct list_head entry;
  29. struct cached_fids *cfids;
  30. const char *path;
  31. bool has_lease:1;
  32. bool is_open:1;
  33. bool on_list:1;
  34. bool file_all_info_is_valid:1;
  35. unsigned long time; /* jiffies of when lease was taken */
  36. struct kref refcount;
  37. struct cifs_fid fid;
  38. spinlock_t fid_lock;
  39. struct cifs_tcon *tcon;
  40. struct dentry *dentry;
  41. struct work_struct lease_break;
  42. struct smb2_file_all_info file_all_info;
  43. struct cached_dirents dirents;
  44. };
  45. #define MAX_CACHED_FIDS 16
  46. struct cached_fids {
  47. /* Must be held when:
  48. * - accessing the cfids->entries list
  49. */
  50. spinlock_t cfid_list_lock;
  51. int num_entries;
  52. struct list_head entries;
  53. };
  54. extern struct cached_fids *init_cached_dirs(void);
  55. extern void free_cached_dirs(struct cached_fids *cfids);
  56. extern int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
  57. const char *path,
  58. struct cifs_sb_info *cifs_sb,
  59. bool lookup_only, struct cached_fid **cfid);
  60. extern int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
  61. struct dentry *dentry,
  62. struct cached_fid **cfid);
  63. extern void close_cached_dir(struct cached_fid *cfid);
  64. extern void drop_cached_dir_by_name(const unsigned int xid,
  65. struct cifs_tcon *tcon,
  66. const char *name,
  67. struct cifs_sb_info *cifs_sb);
  68. extern void close_all_cached_dirs(struct cifs_sb_info *cifs_sb);
  69. extern void invalidate_all_cached_dirs(struct cifs_tcon *tcon);
  70. extern int cached_dir_lease_break(struct cifs_tcon *tcon, __u8 lease_key[16]);
  71. #endif /* _CACHED_DIR_H */