autofs_i.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Copyright 1997-1998 Transmeta Corporation - All Rights Reserved
  3. * Copyright 2005-2006 Ian Kent <raven@themaw.net>
  4. *
  5. * This file is part of the Linux kernel and is made available under
  6. * the terms of the GNU General Public License, version 2, or at your
  7. * option, any later version, incorporated herein by reference.
  8. */
  9. /* Internal header file for autofs */
  10. #include <linux/auto_fs.h>
  11. #include <linux/auto_dev-ioctl.h>
  12. #include <linux/kernel.h>
  13. #include <linux/slab.h>
  14. #include <linux/time.h>
  15. #include <linux/string.h>
  16. #include <linux/wait.h>
  17. #include <linux/sched.h>
  18. #include <linux/sched/signal.h>
  19. #include <linux/mount.h>
  20. #include <linux/namei.h>
  21. #include <linux/uaccess.h>
  22. #include <linux/mutex.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/list.h>
  25. #include <linux/completion.h>
  26. #include <linux/file.h>
  27. #include <linux/magic.h>
  28. /* This is the range of ioctl() numbers we claim as ours */
  29. #define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
  30. #define AUTOFS_IOC_COUNT 32
  31. #define AUTOFS_DEV_IOCTL_IOC_FIRST (AUTOFS_DEV_IOCTL_VERSION)
  32. #define AUTOFS_DEV_IOCTL_IOC_COUNT \
  33. (AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD - AUTOFS_DEV_IOCTL_VERSION_CMD)
  34. #ifdef pr_fmt
  35. #undef pr_fmt
  36. #endif
  37. #define pr_fmt(fmt) KBUILD_MODNAME ":pid:%d:%s: " fmt, current->pid, __func__
  38. /*
  39. * Unified info structure. This is pointed to by both the dentry and
  40. * inode structures. Each file in the filesystem has an instance of this
  41. * structure. It holds a reference to the dentry, so dentries are never
  42. * flushed while the file exists. All name lookups are dealt with at the
  43. * dentry level, although the filesystem can interfere in the validation
  44. * process. Readdir is implemented by traversing the dentry lists.
  45. */
  46. struct autofs_info {
  47. struct dentry *dentry;
  48. struct inode *inode;
  49. int flags;
  50. struct completion expire_complete;
  51. struct list_head active;
  52. int active_count;
  53. struct list_head expiring;
  54. struct autofs_sb_info *sbi;
  55. unsigned long last_used;
  56. atomic_t count;
  57. kuid_t uid;
  58. kgid_t gid;
  59. };
  60. #define AUTOFS_INF_EXPIRING (1<<0) /* dentry in the process of expiring */
  61. #define AUTOFS_INF_WANT_EXPIRE (1<<1) /* the dentry is being considered
  62. * for expiry, so RCU_walk is
  63. * not permitted. If it progresses to
  64. * actual expiry attempt, the flag is
  65. * not cleared when EXPIRING is set -
  66. * in that case it gets cleared only
  67. * when it comes to clearing EXPIRING.
  68. */
  69. #define AUTOFS_INF_PENDING (1<<2) /* dentry pending mount */
  70. struct autofs_wait_queue {
  71. wait_queue_head_t queue;
  72. struct autofs_wait_queue *next;
  73. autofs_wqt_t wait_queue_token;
  74. /* We use the following to see what we are waiting for */
  75. struct qstr name;
  76. u32 dev;
  77. u64 ino;
  78. kuid_t uid;
  79. kgid_t gid;
  80. pid_t pid;
  81. pid_t tgid;
  82. /* This is for status reporting upon return */
  83. int status;
  84. unsigned int wait_ctr;
  85. };
  86. #define AUTOFS_SBI_MAGIC 0x6d4a556d
  87. struct autofs_sb_info {
  88. u32 magic;
  89. int pipefd;
  90. struct file *pipe;
  91. struct pid *oz_pgrp;
  92. int catatonic;
  93. int version;
  94. int sub_version;
  95. int min_proto;
  96. int max_proto;
  97. unsigned long exp_timeout;
  98. unsigned int type;
  99. struct super_block *sb;
  100. struct mutex wq_mutex;
  101. struct mutex pipe_mutex;
  102. spinlock_t fs_lock;
  103. struct autofs_wait_queue *queues; /* Wait queue pointer */
  104. spinlock_t lookup_lock;
  105. struct list_head active_list;
  106. struct list_head expiring_list;
  107. struct rcu_head rcu;
  108. };
  109. static inline struct autofs_sb_info *autofs_sbi(struct super_block *sb)
  110. {
  111. return sb->s_magic != AUTOFS_SUPER_MAGIC ?
  112. NULL : (struct autofs_sb_info *)(sb->s_fs_info);
  113. }
  114. static inline struct autofs_info *autofs_dentry_ino(struct dentry *dentry)
  115. {
  116. return (struct autofs_info *)(dentry->d_fsdata);
  117. }
  118. /* autofs_oz_mode(): do we see the man behind the curtain? (The
  119. * processes which do manipulations for us in user space sees the raw
  120. * filesystem without "magic".)
  121. */
  122. static inline int autofs_oz_mode(struct autofs_sb_info *sbi)
  123. {
  124. return sbi->catatonic || task_pgrp(current) == sbi->oz_pgrp;
  125. }
  126. struct inode *autofs_get_inode(struct super_block *, umode_t);
  127. void autofs_free_ino(struct autofs_info *);
  128. /* Expiration */
  129. int is_autofs_dentry(struct dentry *);
  130. int autofs_expire_wait(const struct path *path, int rcu_walk);
  131. int autofs_expire_run(struct super_block *, struct vfsmount *,
  132. struct autofs_sb_info *,
  133. struct autofs_packet_expire __user *);
  134. int autofs_do_expire_multi(struct super_block *sb, struct vfsmount *mnt,
  135. struct autofs_sb_info *sbi, unsigned int how);
  136. int autofs_expire_multi(struct super_block *, struct vfsmount *,
  137. struct autofs_sb_info *, int __user *);
  138. /* Device node initialization */
  139. int autofs_dev_ioctl_init(void);
  140. void autofs_dev_ioctl_exit(void);
  141. /* Operations structures */
  142. extern const struct inode_operations autofs_symlink_inode_operations;
  143. extern const struct inode_operations autofs_dir_inode_operations;
  144. extern const struct file_operations autofs_dir_operations;
  145. extern const struct file_operations autofs_root_operations;
  146. extern const struct dentry_operations autofs_dentry_operations;
  147. /* VFS automount flags management functions */
  148. static inline void __managed_dentry_set_managed(struct dentry *dentry)
  149. {
  150. dentry->d_flags |= (DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT);
  151. }
  152. static inline void managed_dentry_set_managed(struct dentry *dentry)
  153. {
  154. spin_lock(&dentry->d_lock);
  155. __managed_dentry_set_managed(dentry);
  156. spin_unlock(&dentry->d_lock);
  157. }
  158. static inline void __managed_dentry_clear_managed(struct dentry *dentry)
  159. {
  160. dentry->d_flags &= ~(DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT);
  161. }
  162. static inline void managed_dentry_clear_managed(struct dentry *dentry)
  163. {
  164. spin_lock(&dentry->d_lock);
  165. __managed_dentry_clear_managed(dentry);
  166. spin_unlock(&dentry->d_lock);
  167. }
  168. /* Initializing function */
  169. int autofs_fill_super(struct super_block *, void *, int);
  170. struct autofs_info *autofs_new_ino(struct autofs_sb_info *);
  171. void autofs_clean_ino(struct autofs_info *);
  172. static inline int autofs_prepare_pipe(struct file *pipe)
  173. {
  174. if (!(pipe->f_mode & FMODE_CAN_WRITE))
  175. return -EINVAL;
  176. if (!S_ISFIFO(file_inode(pipe)->i_mode))
  177. return -EINVAL;
  178. /* We want a packet pipe */
  179. pipe->f_flags |= O_DIRECT;
  180. return 0;
  181. }
  182. /* Queue management functions */
  183. int autofs_wait(struct autofs_sb_info *,
  184. const struct path *, enum autofs_notify);
  185. int autofs_wait_release(struct autofs_sb_info *, autofs_wqt_t, int);
  186. void autofs_catatonic_mode(struct autofs_sb_info *);
  187. static inline u32 autofs_get_dev(struct autofs_sb_info *sbi)
  188. {
  189. return new_encode_dev(sbi->sb->s_dev);
  190. }
  191. static inline u64 autofs_get_ino(struct autofs_sb_info *sbi)
  192. {
  193. return d_inode(sbi->sb->s_root)->i_ino;
  194. }
  195. static inline void __autofs_add_expiring(struct dentry *dentry)
  196. {
  197. struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
  198. struct autofs_info *ino = autofs_dentry_ino(dentry);
  199. if (ino) {
  200. if (list_empty(&ino->expiring))
  201. list_add(&ino->expiring, &sbi->expiring_list);
  202. }
  203. }
  204. static inline void autofs_add_expiring(struct dentry *dentry)
  205. {
  206. struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
  207. struct autofs_info *ino = autofs_dentry_ino(dentry);
  208. if (ino) {
  209. spin_lock(&sbi->lookup_lock);
  210. if (list_empty(&ino->expiring))
  211. list_add(&ino->expiring, &sbi->expiring_list);
  212. spin_unlock(&sbi->lookup_lock);
  213. }
  214. }
  215. static inline void autofs_del_expiring(struct dentry *dentry)
  216. {
  217. struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
  218. struct autofs_info *ino = autofs_dentry_ino(dentry);
  219. if (ino) {
  220. spin_lock(&sbi->lookup_lock);
  221. if (!list_empty(&ino->expiring))
  222. list_del_init(&ino->expiring);
  223. spin_unlock(&sbi->lookup_lock);
  224. }
  225. }
  226. void autofs_kill_sb(struct super_block *);