dfs_cache.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * DFS referral cache routines
  4. *
  5. * Copyright (c) 2018-2019 Paulo Alcantara <palcantara@suse.de>
  6. */
  7. #ifndef _CIFS_DFS_CACHE_H
  8. #define _CIFS_DFS_CACHE_H
  9. #include <linux/nls.h>
  10. #include <linux/list.h>
  11. #include <linux/uuid.h>
  12. #include "cifsglob.h"
  13. extern struct workqueue_struct *dfscache_wq;
  14. extern atomic_t dfs_cache_ttl;
  15. #define DFS_CACHE_TGT_LIST_INIT(var) \
  16. { .tl_numtgts = 0, .tl_list = LIST_HEAD_INIT((var).tl_list), }
  17. #define DFS_CACHE_TGT_LIST(var) \
  18. struct dfs_cache_tgt_list var = DFS_CACHE_TGT_LIST_INIT(var)
  19. struct dfs_cache_tgt_list {
  20. int tl_numtgts;
  21. struct list_head tl_list;
  22. };
  23. struct dfs_cache_tgt_iterator {
  24. char *it_name;
  25. int it_path_consumed;
  26. struct list_head it_list;
  27. };
  28. int dfs_cache_init(void);
  29. void dfs_cache_destroy(void);
  30. extern const struct proc_ops dfscache_proc_ops;
  31. int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses, const struct nls_table *cp,
  32. int remap, const char *path, struct dfs_info3_param *ref,
  33. struct dfs_cache_tgt_list *tgt_list);
  34. int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref,
  35. struct dfs_cache_tgt_list *tgt_list);
  36. void dfs_cache_noreq_update_tgthint(const char *path, const struct dfs_cache_tgt_iterator *it);
  37. int dfs_cache_get_tgt_referral(const char *path, const struct dfs_cache_tgt_iterator *it,
  38. struct dfs_info3_param *ref);
  39. int dfs_cache_get_tgt_share(char *path, const struct dfs_cache_tgt_iterator *it, char **share,
  40. char **prefix);
  41. char *dfs_cache_canonical_path(const char *path, const struct nls_table *cp, int remap);
  42. int dfs_cache_remount_fs(struct cifs_sb_info *cifs_sb);
  43. void dfs_cache_refresh(struct work_struct *work);
  44. static inline struct dfs_cache_tgt_iterator *
  45. dfs_cache_get_next_tgt(struct dfs_cache_tgt_list *tl,
  46. struct dfs_cache_tgt_iterator *it)
  47. {
  48. if (!tl || !tl->tl_numtgts || list_empty(&tl->tl_list) ||
  49. !it || list_is_last(&it->it_list, &tl->tl_list))
  50. return NULL;
  51. return list_next_entry(it, it_list);
  52. }
  53. static inline struct dfs_cache_tgt_iterator *
  54. dfs_cache_get_tgt_iterator(struct dfs_cache_tgt_list *tl)
  55. {
  56. if (!tl)
  57. return NULL;
  58. return list_first_entry_or_null(&tl->tl_list,
  59. struct dfs_cache_tgt_iterator,
  60. it_list);
  61. }
  62. static inline void dfs_cache_free_tgts(struct dfs_cache_tgt_list *tl)
  63. {
  64. struct dfs_cache_tgt_iterator *it, *nit;
  65. if (!tl || !tl->tl_numtgts || list_empty(&tl->tl_list))
  66. return;
  67. list_for_each_entry_safe(it, nit, &tl->tl_list, it_list) {
  68. list_del(&it->it_list);
  69. kfree(it->it_name);
  70. kfree(it);
  71. }
  72. tl->tl_numtgts = 0;
  73. }
  74. static inline const char *
  75. dfs_cache_get_tgt_name(const struct dfs_cache_tgt_iterator *it)
  76. {
  77. return it ? it->it_name : NULL;
  78. }
  79. static inline int
  80. dfs_cache_get_nr_tgts(const struct dfs_cache_tgt_list *tl)
  81. {
  82. return tl ? tl->tl_numtgts : 0;
  83. }
  84. static inline int dfs_cache_get_ttl(void)
  85. {
  86. return atomic_read(&dfs_cache_ttl);
  87. }
  88. #endif /* _CIFS_DFS_CACHE_H */