Ejemplo n.º 1
0
int autofs4_fill_super(struct super_block *s, void *data, int silent)
{
	struct inode * root_inode;
	struct dentry * root;
	struct file * pipe;
	int pipefd;
	struct autofs_sb_info *sbi;
	struct autofs_info *ino;

	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
	if (!sbi)
		goto fail_unlock;
	DPRINTK("starting up, sbi = %p",sbi);

	s->s_fs_info = sbi;
	sbi->magic = AUTOFS_SBI_MAGIC;
	sbi->pipefd = -1;
	sbi->pipe = NULL;
	sbi->catatonic = 1;
	sbi->exp_timeout = 0;
	sbi->oz_pgrp = task_pgrp_nr(current);
	sbi->sb = s;
	sbi->version = 0;
	sbi->sub_version = 0;
	set_autofs_type_indirect(&sbi->type);
	sbi->min_proto = 0;
	sbi->max_proto = 0;
	mutex_init(&sbi->wq_mutex);
	spin_lock_init(&sbi->fs_lock);
	sbi->queues = NULL;
	spin_lock_init(&sbi->lookup_lock);
	INIT_LIST_HEAD(&sbi->active_list);
	INIT_LIST_HEAD(&sbi->expiring_list);
	s->s_blocksize = 1024;
	s->s_blocksize_bits = 10;
	s->s_magic = AUTOFS_SUPER_MAGIC;
	s->s_op = &autofs4_sops;
	s->s_time_gran = 1;

	/*
	 * Get the root inode and dentry, but defer checking for errors.
	 */
	ino = autofs4_mkroot(sbi);
	if (!ino)
		goto fail_free;
	root_inode = autofs4_get_inode(s, ino);
	if (!root_inode)
		goto fail_ino;

	root = d_alloc_root(root_inode);
	if (!root)
		goto fail_iput;
	pipe = NULL;

	root->d_op = &autofs4_sb_dentry_operations;
	root->d_fsdata = ino;

	/* Can this call block? */
	if (parse_options(data, &pipefd, &root_inode->i_uid, &root_inode->i_gid,
				&sbi->oz_pgrp, &sbi->type, &sbi->min_proto,
				&sbi->max_proto)) {
		printk("autofs: called with bogus options\n");
		goto fail_dput;
	}

	root_inode->i_fop = &autofs4_root_operations;
	root_inode->i_op = autofs_type_trigger(sbi->type) ?
			&autofs4_direct_root_inode_operations :
			&autofs4_indirect_root_inode_operations;

	/* Couldn't this be tested earlier? */
	if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
	    sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
		printk("autofs: kernel does not match daemon version "
		       "daemon (%d, %d) kernel (%d, %d)\n",
			sbi->min_proto, sbi->max_proto,
			AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
		goto fail_dput;
	}

	/* Establish highest kernel protocol version */
	if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
		sbi->version = AUTOFS_MAX_PROTO_VERSION;
	else
		sbi->version = sbi->max_proto;
	sbi->sub_version = AUTOFS_PROTO_SUBVERSION;

	DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp);
	pipe = fget(pipefd);
	
	if (!pipe) {
		printk("autofs: could not open pipe file descriptor\n");
		goto fail_dput;
	}
	if (!pipe->f_op || !pipe->f_op->write)
		goto fail_fput;
	sbi->pipe = pipe;
	sbi->pipefd = pipefd;
	sbi->catatonic = 0;

	/*
	 * Success! Install the root dentry now to indicate completion.
	 */
	s->s_root = root;
	return 0;
	
	/*
	 * Failure ... clean up.
	 */
fail_fput:
	printk("autofs: pipe file descriptor does not contain proper ops\n");
	fput(pipe);
	/* fall through */
fail_dput:
	dput(root);
	goto fail_free;
fail_iput:
	printk("autofs: get root dentry failed\n");
	iput(root_inode);
fail_ino:
	kfree(ino);
fail_free:
	kfree(sbi);
	s->s_fs_info = NULL;
fail_unlock:
	return -EINVAL;
}
Ejemplo n.º 2
0
struct super_block *autofs4_read_super(struct super_block *s, void *data,
                                       int silent)
{
    struct inode * root_inode;
    struct dentry * root;
    struct file * pipe;
    int pipefd;
    struct autofs_sb_info *sbi;
    int minproto, maxproto;

    sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
    if ( !sbi )
        goto fail_unlock;
    DPRINTK(("autofs: starting up, sbi = %p\n",sbi));

    memset(sbi, 0, sizeof(*sbi));

    s->u.generic_sbp = sbi;
    sbi->magic = AUTOFS_SBI_MAGIC;
    sbi->catatonic = 0;
    sbi->exp_timeout = 0;
    sbi->oz_pgrp = current->pgrp;
    sbi->sb = s;
    sbi->version = 0;
    sbi->queues = NULL;
    s->s_blocksize = 1024;
    s->s_blocksize_bits = 10;
    s->s_magic = AUTOFS_SUPER_MAGIC;
    s->s_op = &autofs4_sops;

    /*
     * Get the root inode and dentry, but defer checking for errors.
     */
    root_inode = autofs4_get_inode(s, autofs4_mkroot(sbi));
    root_inode->i_op = &autofs4_root_inode_operations;
    root_inode->i_fop = &autofs4_root_operations;
    root = d_alloc_root(root_inode);
    pipe = NULL;

    if (!root)
        goto fail_iput;

    /* Can this call block? */
    if (parse_options(data, &pipefd,
                      &root_inode->i_uid, &root_inode->i_gid,
                      &sbi->oz_pgrp,
                      &minproto, &maxproto)) {
        printk("autofs: called with bogus options\n");
        goto fail_dput;
    }

    /* Couldn't this be tested earlier? */
    if (maxproto < AUTOFS_MIN_PROTO_VERSION ||
            minproto > AUTOFS_MAX_PROTO_VERSION) {
        printk("autofs: kernel does not match daemon version "
               "daemon (%d, %d) kernel (%d, %d)\n",
               minproto, maxproto,
               AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
        goto fail_dput;
    }

    sbi->version = maxproto > AUTOFS_MAX_PROTO_VERSION ? AUTOFS_MAX_PROTO_VERSION : maxproto;

    DPRINTK(("autofs: pipe fd = %d, pgrp = %u\n", pipefd, sbi->oz_pgrp));
    pipe = fget(pipefd);

    if ( !pipe ) {
        printk("autofs: could not open pipe file descriptor\n");
        goto fail_dput;
    }
    if ( !pipe->f_op || !pipe->f_op->write )
        goto fail_fput;
    sbi->pipe = pipe;

    /*
     * Success! Install the root dentry now to indicate completion.
     */
    s->s_root = root;
    return s;

    /*
     * Failure ... clean up.
     */
fail_fput:
    printk("autofs: pipe file descriptor does not contain proper ops\n");
    /*
     * fput() can block, so we clear the super block first.
     */
    fput(pipe);
    /* fall through */
fail_dput:
    /*
     * dput() can block, so we clear the super block first.
     */
    dput(root);
    goto fail_free;
fail_iput:
    printk("autofs: get root dentry failed\n");
    /*
     * iput() can block, so we clear the super block first.
     */
    iput(root_inode);
fail_free:
    kfree(sbi);
fail_unlock:
    return NULL;
}