autofs_i.h 7.6 KB

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