1717#include <linux/pagemap.h>
1818#include <linux/ctype.h>
1919#include <linux/sched.h>
20+ #include <linux/dns_resolver.h>
2021#include "internal.h"
2122
2223static struct dentry * afs_lookup (struct inode * dir , struct dentry * dentry ,
2324 unsigned int flags );
25+ static struct dentry * afs_dynroot_lookup (struct inode * dir , struct dentry * dentry ,
26+ unsigned int flags );
2427static int afs_dir_open (struct inode * inode , struct file * file );
2528static int afs_readdir (struct file * file , struct dir_context * ctx );
2629static int afs_d_revalidate (struct dentry * dentry , unsigned int flags );
@@ -64,6 +67,17 @@ const struct inode_operations afs_dir_inode_operations = {
6467 .listxattr = afs_listxattr ,
6568};
6669
70+ const struct file_operations afs_dynroot_file_operations = {
71+ .open = dcache_dir_open ,
72+ .release = dcache_dir_close ,
73+ .iterate_shared = dcache_readdir ,
74+ .llseek = dcache_dir_lseek ,
75+ };
76+
77+ const struct inode_operations afs_dynroot_inode_operations = {
78+ .lookup = afs_dynroot_lookup ,
79+ };
80+
6781const struct dentry_operations afs_fs_dentry_operations = {
6882 .d_revalidate = afs_d_revalidate ,
6983 .d_delete = afs_d_delete ,
@@ -467,26 +481,59 @@ static int afs_do_lookup(struct inode *dir, struct dentry *dentry,
467481 return 0 ;
468482}
469483
484+ /*
485+ * Probe to see if a cell may exist. This prevents positive dentries from
486+ * being created unnecessarily.
487+ */
488+ static int afs_probe_cell_name (struct dentry * dentry )
489+ {
490+ struct afs_cell * cell ;
491+ const char * name = dentry -> d_name .name ;
492+ size_t len = dentry -> d_name .len ;
493+ int ret ;
494+
495+ /* Names prefixed with a dot are R/W mounts. */
496+ if (name [0 ] == '.' ) {
497+ if (len == 1 )
498+ return - EINVAL ;
499+ name ++ ;
500+ len -- ;
501+ }
502+
503+ cell = afs_lookup_cell_rcu (afs_d2net (dentry ), name , len );
504+ if (!IS_ERR (cell )) {
505+ afs_put_cell (afs_d2net (dentry ), cell );
506+ return 0 ;
507+ }
508+
509+ ret = dns_query ("afsdb" , name , len , "ipv4" , NULL , NULL );
510+ if (ret == - ENODATA )
511+ ret = - EDESTADDRREQ ;
512+ return ret ;
513+ }
514+
470515/*
471516 * Try to auto mount the mountpoint with pseudo directory, if the autocell
472517 * operation is setted.
473518 */
474- static struct inode * afs_try_auto_mntpt (
475- int ret , struct dentry * dentry , struct inode * dir , struct key * key ,
476- struct afs_fid * fid )
519+ static struct inode * afs_try_auto_mntpt (struct dentry * dentry ,
520+ struct inode * dir , struct afs_fid * fid )
477521{
478- const char * devname = dentry -> d_name .name ;
479522 struct afs_vnode * vnode = AFS_FS_I (dir );
480523 struct inode * inode ;
524+ int ret = - ENOENT ;
481525
482- _enter ("%d, %p{%pd}, {%x:%u}, %p" ,
483- ret , dentry , dentry , vnode -> fid .vid , vnode -> fid .vnode , key );
526+ _enter ("%p{%pd}, {%x:%u}" ,
527+ dentry , dentry , vnode -> fid .vid , vnode -> fid .vnode );
528+
529+ if (!test_bit (AFS_VNODE_AUTOCELL , & vnode -> flags ))
530+ goto out ;
484531
485- if ( ret != - ENOENT ||
486- ! test_bit ( AFS_VNODE_AUTOCELL , & vnode -> flags ) )
532+ ret = afs_probe_cell_name ( dentry );
533+ if ( ret < 0 )
487534 goto out ;
488535
489- inode = afs_iget_autocell (dir , devname , strlen ( devname ), key );
536+ inode = afs_iget_pseudo_dir (dir -> i_sb , false );
490537 if (IS_ERR (inode )) {
491538 ret = PTR_ERR (inode );
492539 goto out ;
@@ -545,13 +592,16 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
545592
546593 ret = afs_do_lookup (dir , dentry , & fid , key );
547594 if (ret < 0 ) {
548- inode = afs_try_auto_mntpt (ret , dentry , dir , key , & fid );
549- if (!IS_ERR (inode )) {
550- key_put (key );
551- goto success ;
595+ if (ret == - ENOENT ) {
596+ inode = afs_try_auto_mntpt (dentry , dir , & fid );
597+ if (!IS_ERR (inode )) {
598+ key_put (key );
599+ goto success ;
600+ }
601+
602+ ret = PTR_ERR (inode );
552603 }
553604
554- ret = PTR_ERR (inode );
555605 key_put (key );
556606 if (ret == - ENOENT ) {
557607 d_add (dentry , NULL );
@@ -582,13 +632,54 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
582632 return NULL ;
583633}
584634
635+ /*
636+ * Look up an entry in a dynroot directory.
637+ */
638+ static struct dentry * afs_dynroot_lookup (struct inode * dir , struct dentry * dentry ,
639+ unsigned int flags )
640+ {
641+ struct afs_vnode * vnode ;
642+ struct afs_fid fid ;
643+ struct inode * inode ;
644+ int ret ;
645+
646+ vnode = AFS_FS_I (dir );
647+
648+ _enter ("%pd" , dentry );
649+
650+ ASSERTCMP (d_inode (dentry ), = = , NULL );
651+
652+ if (dentry -> d_name .len >= AFSNAMEMAX ) {
653+ _leave (" = -ENAMETOOLONG" );
654+ return ERR_PTR (- ENAMETOOLONG );
655+ }
656+
657+ inode = afs_try_auto_mntpt (dentry , dir , & fid );
658+ if (IS_ERR (inode )) {
659+ ret = PTR_ERR (inode );
660+ if (ret == - ENOENT ) {
661+ d_add (dentry , NULL );
662+ _leave (" = NULL [negative]" );
663+ return NULL ;
664+ }
665+ _leave (" = %d [do]" , ret );
666+ return ERR_PTR (ret );
667+ }
668+
669+ d_add (dentry , inode );
670+ _leave (" = 0 { ino=%lu v=%u }" ,
671+ d_inode (dentry )-> i_ino , d_inode (dentry )-> i_generation );
672+ return NULL ;
673+ }
674+
585675/*
586676 * check that a dentry lookup hit has found a valid entry
587677 * - NOTE! the hit can be a negative hit too, so we can't assume we have an
588678 * inode
589679 */
590680static int afs_d_revalidate (struct dentry * dentry , unsigned int flags )
591681{
682+ struct afs_super_info * as = dentry -> d_sb -> s_fs_info ;
592683 struct afs_vnode * vnode , * dir ;
593684 struct afs_fid uninitialized_var (fid );
594685 struct dentry * parent ;
@@ -600,6 +691,9 @@ static int afs_d_revalidate(struct dentry *dentry, unsigned int flags)
600691 if (flags & LOOKUP_RCU )
601692 return - ECHILD ;
602693
694+ if (as -> dyn_root )
695+ return 1 ;
696+
603697 if (d_really_is_positive (dentry )) {
604698 vnode = AFS_FS_I (d_inode (dentry ));
605699 _enter ("{v={%x:%u} n=%pd fl=%lx}," ,
0 commit comments