Merge tag 'pci-v5.16-fixes-1' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaa...
[linux-block.git] / fs / cifs / dfs_cache.h
CommitLineData
54be1f6c
PA
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * DFS referral cache routines
4 *
5072010c 5 * Copyright (c) 2018-2019 Paulo Alcantara <palcantara@suse.de>
54be1f6c
PA
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>
c9f71103 13#include <linux/uuid.h>
54be1f6c
PA
14#include "cifsglob.h"
15
b6236618
PA
16#define DFS_CACHE_TGT_LIST_INIT(var) { .tl_numtgts = 0, .tl_list = LIST_HEAD_INIT((var).tl_list), }
17
54be1f6c
PA
18struct dfs_cache_tgt_list {
19 int tl_numtgts;
20 struct list_head tl_list;
21};
22
23struct dfs_cache_tgt_iterator {
24 char *it_name;
7548e1da 25 int it_path_consumed;
54be1f6c
PA
26 struct list_head it_list;
27};
28
c870a8e7
PA
29int dfs_cache_init(void);
30void dfs_cache_destroy(void);
97a32539 31extern const struct proc_ops dfscache_proc_ops;
54be1f6c 32
c870a8e7
PA
33int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses, const struct nls_table *cp,
34 int remap, const char *path, struct dfs_info3_param *ref,
35 struct dfs_cache_tgt_list *tgt_list);
36int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref,
37 struct dfs_cache_tgt_list *tgt_list);
38int dfs_cache_update_tgthint(const unsigned int xid, struct cifs_ses *ses,
39 const struct nls_table *cp, int remap, const char *path,
40 const struct dfs_cache_tgt_iterator *it);
41int dfs_cache_noreq_update_tgthint(const char *path, const struct dfs_cache_tgt_iterator *it);
42int dfs_cache_get_tgt_referral(const char *path, const struct dfs_cache_tgt_iterator *it,
43 struct dfs_info3_param *ref);
44int dfs_cache_get_tgt_share(char *path, const struct dfs_cache_tgt_iterator *it, char **share,
45 char **prefix);
c9f71103
PA
46void dfs_cache_put_refsrv_sessions(const uuid_t *mount_id);
47void dfs_cache_add_refsrv_session(const uuid_t *mount_id, struct cifs_ses *ses);
c870a8e7 48char *dfs_cache_canonical_path(const char *path, const struct nls_table *cp, int remap);
b6236618 49int dfs_cache_remount_fs(struct cifs_sb_info *cifs_sb);
bacd704a 50
54be1f6c
PA
51static inline struct dfs_cache_tgt_iterator *
52dfs_cache_get_next_tgt(struct dfs_cache_tgt_list *tl,
53 struct dfs_cache_tgt_iterator *it)
54{
55 if (!tl || list_empty(&tl->tl_list) || !it ||
56 list_is_last(&it->it_list, &tl->tl_list))
57 return NULL;
58 return list_next_entry(it, it_list);
59}
60
61static inline struct dfs_cache_tgt_iterator *
62dfs_cache_get_tgt_iterator(struct dfs_cache_tgt_list *tl)
63{
64 if (!tl)
65 return NULL;
66 return list_first_entry_or_null(&tl->tl_list,
67 struct dfs_cache_tgt_iterator,
68 it_list);
69}
70
71static inline void dfs_cache_free_tgts(struct dfs_cache_tgt_list *tl)
72{
73 struct dfs_cache_tgt_iterator *it, *nit;
74
75 if (!tl || list_empty(&tl->tl_list))
76 return;
77 list_for_each_entry_safe(it, nit, &tl->tl_list, it_list) {
78 list_del(&it->it_list);
79 kfree(it->it_name);
80 kfree(it);
81 }
82 tl->tl_numtgts = 0;
83}
84
85static inline const char *
86dfs_cache_get_tgt_name(const struct dfs_cache_tgt_iterator *it)
87{
88 return it ? it->it_name : NULL;
89}
90
91static inline int
92dfs_cache_get_nr_tgts(const struct dfs_cache_tgt_list *tl)
93{
94 return tl ? tl->tl_numtgts : 0;
95}
96
97#endif /* _CIFS_DFS_CACHE_H */