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