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 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 15struct dfs_cache_tgt_list { 16 int tl_numtgts; 17 struct list_head tl_list; 18}; 19 20struct dfs_cache_tgt_iterator { 21 char *it_name; 22 int it_path_consumed; 23 struct list_head it_list; 24}; 25 26extern int dfs_cache_init(void); 27extern void dfs_cache_destroy(void); 28extern const struct proc_ops dfscache_proc_ops; 29 30extern 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); 34extern int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref, 35 struct dfs_cache_tgt_list *tgt_list); 36extern 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); 41extern int 42dfs_cache_noreq_update_tgthint(const char *path, 43 const struct dfs_cache_tgt_iterator *it); 44extern int dfs_cache_get_tgt_referral(const char *path, 45 const struct dfs_cache_tgt_iterator *it, 46 struct dfs_info3_param *ref); 47extern int dfs_cache_add_vol(char *mntdata, struct smb_vol *vol, 48 const char *fullpath); 49extern int dfs_cache_update_vol(const char *fullpath, 50 struct TCP_Server_Info *server); 51extern void dfs_cache_del_vol(const char *fullpath); 52extern int dfs_cache_get_tgt_share(char *path, const struct dfs_cache_tgt_iterator *it, 53 char **share, char **prefix); 54 55static inline struct dfs_cache_tgt_iterator * 56dfs_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 65static inline struct dfs_cache_tgt_iterator * 66dfs_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 75static 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 89static inline const char * 90dfs_cache_get_tgt_name(const struct dfs_cache_tgt_iterator *it) 91{ 92 return it ? it->it_name : NULL; 93} 94 95static inline int 96dfs_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 */ 102