LCOV - code coverage report
Current view: top level - fs/autofs4 - inode.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 154 0.0 %
Date: 2014-02-18 Functions: 0 9 0.0 %
Branches: 0 76 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- c -*- --------------------------------------------------------------- *
       2                 :            :  *
       3                 :            :  * linux/fs/autofs/inode.c
       4                 :            :  *
       5                 :            :  *  Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
       6                 :            :  *  Copyright 2005-2006 Ian Kent <raven@themaw.net>
       7                 :            :  *
       8                 :            :  * This file is part of the Linux kernel and is made available under
       9                 :            :  * the terms of the GNU General Public License, version 2, or at your
      10                 :            :  * option, any later version, incorporated herein by reference.
      11                 :            :  *
      12                 :            :  * ------------------------------------------------------------------------- */
      13                 :            : 
      14                 :            : #include <linux/kernel.h>
      15                 :            : #include <linux/slab.h>
      16                 :            : #include <linux/file.h>
      17                 :            : #include <linux/seq_file.h>
      18                 :            : #include <linux/pagemap.h>
      19                 :            : #include <linux/parser.h>
      20                 :            : #include <linux/bitops.h>
      21                 :            : #include <linux/magic.h>
      22                 :            : #include "autofs_i.h"
      23                 :            : #include <linux/module.h>
      24                 :            : 
      25                 :          0 : struct autofs_info *autofs4_new_ino(struct autofs_sb_info *sbi)
      26                 :            : {
      27                 :            :         struct autofs_info *ino = kzalloc(sizeof(*ino), GFP_KERNEL);
      28         [ #  # ]:          0 :         if (ino) {
      29                 :          0 :                 INIT_LIST_HEAD(&ino->active);
      30                 :          0 :                 INIT_LIST_HEAD(&ino->expiring);
      31                 :          0 :                 ino->last_used = jiffies;
      32                 :          0 :                 ino->sbi = sbi;
      33                 :            :         }
      34                 :          0 :         return ino;
      35                 :            : }
      36                 :            : 
      37                 :          0 : void autofs4_clean_ino(struct autofs_info *ino)
      38                 :            : {
      39                 :          0 :         ino->uid = GLOBAL_ROOT_UID;
      40                 :          0 :         ino->gid = GLOBAL_ROOT_GID;
      41                 :          0 :         ino->last_used = jiffies;
      42                 :          0 : }
      43                 :            : 
      44                 :          0 : void autofs4_free_ino(struct autofs_info *ino)
      45                 :            : {
      46                 :          0 :         kfree(ino);
      47                 :          0 : }
      48                 :            : 
      49                 :          0 : void autofs4_kill_sb(struct super_block *sb)
      50                 :            : {
      51                 :            :         struct autofs_sb_info *sbi = autofs4_sbi(sb);
      52                 :            : 
      53                 :            :         /*
      54                 :            :          * In the event of a failure in get_sb_nodev the superblock
      55                 :            :          * info is not present so nothing else has been setup, so
      56                 :            :          * just call kill_anon_super when we are called from
      57                 :            :          * deactivate_super.
      58                 :            :          */
      59         [ #  # ]:          0 :         if (sbi) /* Free wait queues, close pipe */
      60                 :          0 :                 autofs4_catatonic_mode(sbi);
      61                 :            : 
      62                 :            :         DPRINTK("shutting down");
      63                 :          0 :         kill_litter_super(sb);
      64         [ #  # ]:          0 :         if (sbi)
      65                 :          0 :                 kfree_rcu(sbi, rcu);
      66                 :          0 : }
      67                 :            : 
      68                 :          0 : static int autofs4_show_options(struct seq_file *m, struct dentry *root)
      69                 :            : {
      70                 :          0 :         struct autofs_sb_info *sbi = autofs4_sbi(root->d_sb);
      71                 :          0 :         struct inode *root_inode = root->d_sb->s_root->d_inode;
      72                 :            : 
      73         [ #  # ]:          0 :         if (!sbi)
      74                 :            :                 return 0;
      75                 :            : 
      76                 :          0 :         seq_printf(m, ",fd=%d", sbi->pipefd);
      77         [ #  # ]:          0 :         if (!uid_eq(root_inode->i_uid, GLOBAL_ROOT_UID))
      78                 :          0 :                 seq_printf(m, ",uid=%u",
      79                 :            :                         from_kuid_munged(&init_user_ns, root_inode->i_uid));
      80         [ #  # ]:          0 :         if (!gid_eq(root_inode->i_gid, GLOBAL_ROOT_GID))
      81                 :          0 :                 seq_printf(m, ",gid=%u",
      82                 :            :                         from_kgid_munged(&init_user_ns, root_inode->i_gid));
      83                 :          0 :         seq_printf(m, ",pgrp=%d", sbi->oz_pgrp);
      84                 :          0 :         seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ);
      85                 :          0 :         seq_printf(m, ",minproto=%d", sbi->min_proto);
      86                 :          0 :         seq_printf(m, ",maxproto=%d", sbi->max_proto);
      87                 :            : 
      88         [ #  # ]:          0 :         if (autofs_type_offset(sbi->type))
      89                 :          0 :                 seq_printf(m, ",offset");
      90         [ #  # ]:          0 :         else if (autofs_type_direct(sbi->type))
      91                 :          0 :                 seq_printf(m, ",direct");
      92                 :            :         else
      93                 :          0 :                 seq_printf(m, ",indirect");
      94                 :            : 
      95                 :            :         return 0;
      96                 :            : }
      97                 :            : 
      98                 :          0 : static void autofs4_evict_inode(struct inode *inode)
      99                 :            : {
     100                 :          0 :         clear_inode(inode);
     101                 :          0 :         kfree(inode->i_private);
     102                 :          0 : }
     103                 :            : 
     104                 :            : static const struct super_operations autofs4_sops = {
     105                 :            :         .statfs         = simple_statfs,
     106                 :            :         .show_options   = autofs4_show_options,
     107                 :            :         .evict_inode    = autofs4_evict_inode,
     108                 :            : };
     109                 :            : 
     110                 :            : enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto,
     111                 :            :         Opt_indirect, Opt_direct, Opt_offset};
     112                 :            : 
     113                 :            : static const match_table_t tokens = {
     114                 :            :         {Opt_fd, "fd=%u"},
     115                 :            :         {Opt_uid, "uid=%u"},
     116                 :            :         {Opt_gid, "gid=%u"},
     117                 :            :         {Opt_pgrp, "pgrp=%u"},
     118                 :            :         {Opt_minproto, "minproto=%u"},
     119                 :            :         {Opt_maxproto, "maxproto=%u"},
     120                 :            :         {Opt_indirect, "indirect"},
     121                 :            :         {Opt_direct, "direct"},
     122                 :            :         {Opt_offset, "offset"},
     123                 :            :         {Opt_err, NULL}
     124                 :            : };
     125                 :            : 
     126                 :          0 : static int parse_options(char *options, int *pipefd, kuid_t *uid, kgid_t *gid,
     127                 :            :                 pid_t *pgrp, unsigned int *type, int *minproto, int *maxproto)
     128                 :            : {
     129                 :            :         char *p;
     130                 :            :         substring_t args[MAX_OPT_ARGS];
     131                 :            :         int option;
     132                 :            : 
     133                 :          0 :         *uid = current_uid();
     134                 :          0 :         *gid = current_gid();
     135                 :          0 :         *pgrp = task_pgrp_nr(current);
     136                 :            : 
     137                 :          0 :         *minproto = AUTOFS_MIN_PROTO_VERSION;
     138                 :          0 :         *maxproto = AUTOFS_MAX_PROTO_VERSION;
     139                 :            : 
     140                 :          0 :         *pipefd = -1;
     141                 :            : 
     142         [ #  # ]:          0 :         if (!options)
     143                 :            :                 return 1;
     144                 :            : 
     145         [ #  # ]:          0 :         while ((p = strsep(&options, ",")) != NULL) {
     146                 :            :                 int token;
     147         [ #  # ]:          0 :                 if (!*p)
     148                 :          0 :                         continue;
     149                 :            : 
     150                 :          0 :                 token = match_token(p, tokens, args);
     151   [ #  #  #  #  :          0 :                 switch (token) {
          #  #  #  #  #  
                      # ]
     152                 :            :                 case Opt_fd:
     153         [ #  # ]:          0 :                         if (match_int(args, pipefd))
     154                 :            :                                 return 1;
     155                 :            :                         break;
     156                 :            :                 case Opt_uid:
     157         [ #  # ]:          0 :                         if (match_int(args, &option))
     158                 :            :                                 return 1;
     159                 :          0 :                         *uid = make_kuid(current_user_ns(), option);
     160         [ #  # ]:          0 :                         if (!uid_valid(*uid))
     161                 :            :                                 return 1;
     162                 :            :                         break;
     163                 :            :                 case Opt_gid:
     164         [ #  # ]:          0 :                         if (match_int(args, &option))
     165                 :            :                                 return 1;
     166                 :          0 :                         *gid = make_kgid(current_user_ns(), option);
     167         [ #  # ]:          0 :                         if (!gid_valid(*gid))
     168                 :            :                                 return 1;
     169                 :            :                         break;
     170                 :            :                 case Opt_pgrp:
     171         [ #  # ]:          0 :                         if (match_int(args, &option))
     172                 :            :                                 return 1;
     173                 :          0 :                         *pgrp = option;
     174                 :          0 :                         break;
     175                 :            :                 case Opt_minproto:
     176         [ #  # ]:          0 :                         if (match_int(args, &option))
     177                 :            :                                 return 1;
     178                 :          0 :                         *minproto = option;
     179                 :          0 :                         break;
     180                 :            :                 case Opt_maxproto:
     181         [ #  # ]:          0 :                         if (match_int(args, &option))
     182                 :            :                                 return 1;
     183                 :          0 :                         *maxproto = option;
     184                 :          0 :                         break;
     185                 :            :                 case Opt_indirect:
     186                 :            :                         set_autofs_type_indirect(type);
     187                 :            :                         break;
     188                 :            :                 case Opt_direct:
     189                 :            :                         set_autofs_type_direct(type);
     190                 :            :                         break;
     191                 :            :                 case Opt_offset:
     192                 :            :                         set_autofs_type_offset(type);
     193                 :            :                         break;
     194                 :            :                 default:
     195                 :            :                         return 1;
     196                 :            :                 }
     197                 :            :         }
     198                 :          0 :         return (*pipefd < 0);
     199                 :            : }
     200                 :            : 
     201                 :          0 : int autofs4_fill_super(struct super_block *s, void *data, int silent)
     202                 :            : {
     203                 :            :         struct inode * root_inode;
     204                 :            :         struct dentry * root;
     205                 :            :         struct file * pipe;
     206                 :            :         int pipefd;
     207                 :            :         struct autofs_sb_info *sbi;
     208                 :            :         struct autofs_info *ino;
     209                 :            : 
     210                 :            :         sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
     211         [ #  # ]:          0 :         if (!sbi)
     212                 :            :                 goto fail_unlock;
     213                 :            :         DPRINTK("starting up, sbi = %p",sbi);
     214                 :            : 
     215                 :          0 :         s->s_fs_info = sbi;
     216                 :          0 :         sbi->magic = AUTOFS_SBI_MAGIC;
     217                 :          0 :         sbi->pipefd = -1;
     218                 :          0 :         sbi->pipe = NULL;
     219                 :          0 :         sbi->catatonic = 1;
     220                 :          0 :         sbi->exp_timeout = 0;
     221                 :          0 :         sbi->oz_pgrp = task_pgrp_nr(current);
     222                 :          0 :         sbi->sb = s;
     223                 :          0 :         sbi->version = 0;
     224                 :          0 :         sbi->sub_version = 0;
     225                 :            :         set_autofs_type_indirect(&sbi->type);
     226                 :          0 :         sbi->min_proto = 0;
     227                 :          0 :         sbi->max_proto = 0;
     228                 :          0 :         mutex_init(&sbi->wq_mutex);
     229                 :          0 :         mutex_init(&sbi->pipe_mutex);
     230                 :          0 :         spin_lock_init(&sbi->fs_lock);
     231                 :          0 :         sbi->queues = NULL;
     232                 :          0 :         spin_lock_init(&sbi->lookup_lock);
     233                 :          0 :         INIT_LIST_HEAD(&sbi->active_list);
     234                 :          0 :         INIT_LIST_HEAD(&sbi->expiring_list);
     235                 :          0 :         s->s_blocksize = 1024;
     236                 :          0 :         s->s_blocksize_bits = 10;
     237                 :          0 :         s->s_magic = AUTOFS_SUPER_MAGIC;
     238                 :          0 :         s->s_op = &autofs4_sops;
     239                 :          0 :         s->s_d_op = &autofs4_dentry_operations;
     240                 :          0 :         s->s_time_gran = 1;
     241                 :            : 
     242                 :            :         /*
     243                 :            :          * Get the root inode and dentry, but defer checking for errors.
     244                 :            :          */
     245                 :          0 :         ino = autofs4_new_ino(sbi);
     246         [ #  # ]:          0 :         if (!ino)
     247                 :            :                 goto fail_free;
     248                 :          0 :         root_inode = autofs4_get_inode(s, S_IFDIR | 0755);
     249                 :          0 :         root = d_make_root(root_inode);
     250         [ #  # ]:          0 :         if (!root)
     251                 :            :                 goto fail_ino;
     252                 :            :         pipe = NULL;
     253                 :            : 
     254                 :          0 :         root->d_fsdata = ino;
     255                 :            : 
     256                 :            :         /* Can this call block? */
     257         [ #  # ]:          0 :         if (parse_options(data, &pipefd, &root_inode->i_uid, &root_inode->i_gid,
     258                 :            :                                 &sbi->oz_pgrp, &sbi->type, &sbi->min_proto,
     259                 :            :                                 &sbi->max_proto)) {
     260                 :          0 :                 printk("autofs: called with bogus options\n");
     261                 :          0 :                 goto fail_dput;
     262                 :            :         }
     263                 :            : 
     264         [ #  # ]:          0 :         if (autofs_type_trigger(sbi->type))
     265                 :            :                 __managed_dentry_set_managed(root);
     266                 :            : 
     267                 :          0 :         root_inode->i_fop = &autofs4_root_operations;
     268                 :          0 :         root_inode->i_op = &autofs4_dir_inode_operations;
     269                 :            : 
     270                 :            :         /* Couldn't this be tested earlier? */
     271 [ #  # ][ #  # ]:          0 :         if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
     272                 :          0 :             sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
     273                 :          0 :                 printk("autofs: kernel does not match daemon version "
     274                 :            :                        "daemon (%d, %d) kernel (%d, %d)\n",
     275                 :            :                         sbi->min_proto, sbi->max_proto,
     276                 :            :                         AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
     277                 :          0 :                 goto fail_dput;
     278                 :            :         }
     279                 :            : 
     280                 :            :         /* Establish highest kernel protocol version */
     281         [ #  # ]:          0 :         if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
     282                 :          0 :                 sbi->version = AUTOFS_MAX_PROTO_VERSION;
     283                 :            :         else
     284                 :          0 :                 sbi->version = sbi->max_proto;
     285                 :          0 :         sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
     286                 :            : 
     287                 :            :         DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp);
     288                 :          0 :         pipe = fget(pipefd);
     289                 :            :         
     290         [ #  # ]:          0 :         if (!pipe) {
     291                 :          0 :                 printk("autofs: could not open pipe file descriptor\n");
     292                 :          0 :                 goto fail_dput;
     293                 :            :         }
     294         [ #  # ]:          0 :         if (autofs_prepare_pipe(pipe) < 0)
     295                 :            :                 goto fail_fput;
     296                 :          0 :         sbi->pipe = pipe;
     297                 :          0 :         sbi->pipefd = pipefd;
     298                 :          0 :         sbi->catatonic = 0;
     299                 :            : 
     300                 :            :         /*
     301                 :            :          * Success! Install the root dentry now to indicate completion.
     302                 :            :          */
     303                 :          0 :         s->s_root = root;
     304                 :          0 :         return 0;
     305                 :            :         
     306                 :            :         /*
     307                 :            :          * Failure ... clean up.
     308                 :            :          */
     309                 :            : fail_fput:
     310                 :          0 :         printk("autofs: pipe file descriptor does not contain proper ops\n");
     311                 :          0 :         fput(pipe);
     312                 :            :         /* fall through */
     313                 :            : fail_dput:
     314                 :          0 :         dput(root);
     315                 :          0 :         goto fail_free;
     316                 :            : fail_ino:
     317                 :          0 :         kfree(ino);
     318                 :            : fail_free:
     319                 :          0 :         kfree(sbi);
     320                 :          0 :         s->s_fs_info = NULL;
     321                 :            : fail_unlock:
     322                 :            :         return -EINVAL;
     323                 :            : }
     324                 :            : 
     325                 :          0 : struct inode *autofs4_get_inode(struct super_block *sb, umode_t mode)
     326                 :            : {
     327                 :          0 :         struct inode *inode = new_inode(sb);
     328                 :            : 
     329         [ #  # ]:          0 :         if (inode == NULL)
     330                 :            :                 return NULL;
     331                 :            : 
     332                 :          0 :         inode->i_mode = mode;
     333         [ #  # ]:          0 :         if (sb->s_root) {
     334                 :          0 :                 inode->i_uid = sb->s_root->d_inode->i_uid;
     335                 :          0 :                 inode->i_gid = sb->s_root->d_inode->i_gid;
     336                 :            :         }
     337                 :          0 :         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
     338                 :          0 :         inode->i_ino = get_next_ino();
     339                 :            : 
     340         [ #  # ]:          0 :         if (S_ISDIR(mode)) {
     341                 :          0 :                 set_nlink(inode, 2);
     342                 :          0 :                 inode->i_op = &autofs4_dir_inode_operations;
     343                 :          0 :                 inode->i_fop = &autofs4_dir_operations;
     344         [ #  # ]:          0 :         } else if (S_ISLNK(mode)) {
     345                 :          0 :                 inode->i_op = &autofs4_symlink_inode_operations;
     346                 :            :         }
     347                 :            : 
     348                 :          0 :         return inode;
     349                 :            : }

Generated by: LCOV version 1.9