Paulo Alcantara | 54be1f6 | 2018-11-14 16:01:21 -0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * DFS referral cache routines |
| 4 | * |
Paulo Alcantara (SUSE) | 5072010 | 2019-03-19 16:54:29 -0300 | [diff] [blame] | 5 | * Copyright (c) 2018-2019 Paulo Alcantara <palcantara@suse.de> |
Paulo Alcantara | 54be1f6 | 2018-11-14 16:01:21 -0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _CIFS_DFS_CACHE_H |
| 9 | #define _CIFS_DFS_CACHE_H |
| 10 | |
| 11 | #include <linux/nls.h> |
| 12 | #include <linux/list.h> |
| 13 | #include "cifsglob.h" |
| 14 | |
| 15 | struct dfs_cache_tgt_list { |
| 16 | int tl_numtgts; |
| 17 | struct list_head tl_list; |
| 18 | }; |
| 19 | |
| 20 | struct dfs_cache_tgt_iterator { |
| 21 | char *it_name; |
Paulo Alcantara | 7548e1d | 2020-07-21 09:36:42 -0300 | [diff] [blame] | 22 | int it_path_consumed; |
Paulo Alcantara | 54be1f6 | 2018-11-14 16:01:21 -0200 | [diff] [blame] | 23 | struct list_head it_list; |
| 24 | }; |
| 25 | |
| 26 | extern int dfs_cache_init(void); |
| 27 | extern void dfs_cache_destroy(void); |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 28 | extern const struct proc_ops dfscache_proc_ops; |
Paulo Alcantara | 54be1f6 | 2018-11-14 16:01:21 -0200 | [diff] [blame] | 29 | |
| 30 | extern int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses, |
| 31 | const struct nls_table *nls_codepage, int remap, |
| 32 | const char *path, struct dfs_info3_param *ref, |
| 33 | struct dfs_cache_tgt_list *tgt_list); |
| 34 | extern int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref, |
| 35 | struct dfs_cache_tgt_list *tgt_list); |
| 36 | extern int dfs_cache_update_tgthint(const unsigned int xid, |
| 37 | struct cifs_ses *ses, |
| 38 | const struct nls_table *nls_codepage, |
| 39 | int remap, const char *path, |
| 40 | const struct dfs_cache_tgt_iterator *it); |
| 41 | extern int |
| 42 | dfs_cache_noreq_update_tgthint(const char *path, |
| 43 | const struct dfs_cache_tgt_iterator *it); |
| 44 | extern int dfs_cache_get_tgt_referral(const char *path, |
| 45 | const struct dfs_cache_tgt_iterator *it, |
| 46 | struct dfs_info3_param *ref); |
Paulo Alcantara (SUSE) | 5072010 | 2019-03-19 16:54:29 -0300 | [diff] [blame] | 47 | extern int dfs_cache_add_vol(char *mntdata, struct smb_vol *vol, |
| 48 | const char *fullpath); |
Paulo Alcantara | 54be1f6 | 2018-11-14 16:01:21 -0200 | [diff] [blame] | 49 | extern int dfs_cache_update_vol(const char *fullpath, |
| 50 | struct TCP_Server_Info *server); |
| 51 | extern void dfs_cache_del_vol(const char *fullpath); |
Paulo Alcantara | 7548e1d | 2020-07-21 09:36:42 -0300 | [diff] [blame] | 52 | extern int dfs_cache_get_tgt_share(char *path, const struct dfs_cache_tgt_iterator *it, |
| 53 | char **share, char **prefix); |
Paulo Alcantara (SUSE) | bacd704 | 2020-02-20 19:49:34 -0300 | [diff] [blame] | 54 | |
Paulo Alcantara | 54be1f6 | 2018-11-14 16:01:21 -0200 | [diff] [blame] | 55 | static inline struct dfs_cache_tgt_iterator * |
| 56 | dfs_cache_get_next_tgt(struct dfs_cache_tgt_list *tl, |
| 57 | struct dfs_cache_tgt_iterator *it) |
| 58 | { |
| 59 | if (!tl || list_empty(&tl->tl_list) || !it || |
| 60 | list_is_last(&it->it_list, &tl->tl_list)) |
| 61 | return NULL; |
| 62 | return list_next_entry(it, it_list); |
| 63 | } |
| 64 | |
| 65 | static inline struct dfs_cache_tgt_iterator * |
| 66 | dfs_cache_get_tgt_iterator(struct dfs_cache_tgt_list *tl) |
| 67 | { |
| 68 | if (!tl) |
| 69 | return NULL; |
| 70 | return list_first_entry_or_null(&tl->tl_list, |
| 71 | struct dfs_cache_tgt_iterator, |
| 72 | it_list); |
| 73 | } |
| 74 | |
| 75 | static inline void dfs_cache_free_tgts(struct dfs_cache_tgt_list *tl) |
| 76 | { |
| 77 | struct dfs_cache_tgt_iterator *it, *nit; |
| 78 | |
| 79 | if (!tl || list_empty(&tl->tl_list)) |
| 80 | return; |
| 81 | list_for_each_entry_safe(it, nit, &tl->tl_list, it_list) { |
| 82 | list_del(&it->it_list); |
| 83 | kfree(it->it_name); |
| 84 | kfree(it); |
| 85 | } |
| 86 | tl->tl_numtgts = 0; |
| 87 | } |
| 88 | |
| 89 | static inline const char * |
| 90 | dfs_cache_get_tgt_name(const struct dfs_cache_tgt_iterator *it) |
| 91 | { |
| 92 | return it ? it->it_name : NULL; |
| 93 | } |
| 94 | |
| 95 | static inline int |
| 96 | dfs_cache_get_nr_tgts(const struct dfs_cache_tgt_list *tl) |
| 97 | { |
| 98 | return tl ? tl->tl_numtgts : 0; |
| 99 | } |
| 100 | |
| 101 | #endif /* _CIFS_DFS_CACHE_H */ |