Sie sind auf Seite 1von 36

HackingtheLinuxAutomounter LinuxKongress2005

JeffMoyer <jmoyer@redhat.com> SeniorSoftwareEngineer

Overview

Whatistheautomounter? Configuration Linuximplementation What'stocome:autofsv5 Contributing

Whatistheautomounter?

Automaticallymountandunmountfilesystems

NFS Localfilesystem(bindmounts) Samba* etc.

Why?

Manageability! ThisgoalisnotachievedbythecurrentLinuxautomounter.

ConfigurationTheMasterMap

auto.master(Linux)orauto_master(UNIX) Sourceofallfurtherconfiguration

whereautomountownedfilesystemsaretobemounted nameofthemapfiletoread Format:mountpointmapname[mountoptions]

mountpoint

fullpathtothedirectoryusedasamountpoint ifitdoesnotexist,itiscreated
'+'ifthemapisanincludedmap. '/'ifthisisadirectmap

TheMasterMap(cont'd)

mapname

Mapfiletoread
'hosts'ifthemapistobeaslashnetmap 'null'ifwewanttooverrideaspecificmapentry

Usefulwhenusedinconjunctionwithincludedmaps

mountoptions

Justwhatitsays,optionswhicharepassedtothemountcommand

#Sampleauto.master /misc /net /nfs / /etc/auto.misc hosts auto_nfs /etc/auto.direct

+auto_master

MountMaps

IndirectMaps

Describethemountpoints,ordirectoryhierarchy,underthedirectory specifiedinthemastermap* Containalistoffulldirectorypathsandthelocationfromwhichthefile systemistobemounted

DirectMaps

Format:key[mountoptions]location
key

directorynamebeinglookedup forindirectmaps,thisisarelativepathstartingfromtheautomountdirectory fordirectmaps,thisisafullpath

MountMaps(cont'd)

mountoptions

optional,commaseparatedlistofoptionsappliedtothemountentry maybefilesystemmountoptions,ormapoptions(suchasDOS=RHEL3) specifiesthefilesystemtobemountedonkey conformstooneofthefollowing


location

singlefilesystem(simplecase) replicatedserverentry multimountentry pathsbeginningwitha'/'mustbeescapedwitha':'

ReplicatedServerEntries

Supportmultiple,typicallyreadonlysourcesofthesamedata(GFS,anyone?) Entriescanbeweighted Entriescancomefromdifferentpathsondifferentservers Serverselectionfollowsthepriority:


lowestweight closestnetworkproximity

/usr/share/manroserver1,server2,server3:/export/share/man /usr/share/docroserver1(50):/export/share/doc,server2:/export/share/doc

UNIXautomounterimplementationsprovidemultipleserverstothemount command.NFStakescareofswitchingserverswhenonedoesn'trespond.

MultimountMaps

Allowforthespecificationofanentiredirectoryhierarchyasasinglemapentry Mountoptionscanbespecifiedpermountpoint Allowsonetocobbletogetheradirectoryhierarchyfrommultipleservers Getsaroundthenonestedmountslimitation

server1rw\ /server1:/export/\ /binroserver1:/export/bin\ /usrserver1:/export/usr\ /usr/binroserver2:/export/usr/bin\ /scratchserver2:/export/scratch

MultiMountMaps(cont'd)

autofs4limitations

mountedandunmountedasasingleunit /netisimplementedasamultimountmap cancauseMANYdirectoriestobemountedatonce

putspressureonreservedportspace

WildCardKeys
Examplemountmap,auto.misc:
music * myserver:/export/music myserver:/export/&

SpecialCharacters

*Thewildcardentry &substituteswhateverwasenteredasthekey #commentcharacter

NameServiceSwitch

/etc/nsswitch.conf Intheory,oneinterfacetoaccessmultiplebackingstores Nosupportinlibcforautofs Currentalgorithmhasnothingtodowiththeorderinnsswitch.conf!


ifitstartswith'/'andisexecutable,it'saprogrammap ifitstartswith'/etc/'andisexecutable,it'saprogrammap ifitstartswith'/'andisafile,it'safilemap ifitstartswith'/etc/'andisafile,it'safilemap else,it'saypmap RedHatpackagesconsultnsswitch.confwhendeterminingthesourceofa submountmap

Exception:

SpecialMaps

hosts

treatskeyasaservername performsashowmounteonkeyandsortstheoutput generatesamultimountentryandmountsit browsingnotrecommended Specifiedtonullifyamap Mustbespecifiedbeforetheentrytobedisregarded


null /etc/auto.home

null

/home +auto_master /home

IncludedMaps

Incorporatesthecontentsofanothermapfileintothecurrentmap

auto.master: /home /nfs auto.home auto.nfs +auto_master

auto_master: /site RESULT: /home /site /nfs auto.home auto.site auto.nfs auto.site

MultiMapEntries

Onlysupportedinauto.master,andonlysupportedunderLinux
/home fileauto.homeypauto_home

thelatermapsaresimplyappendedtothefirst nolimitonthenumberofmapstoconcatenate CollisionsareOK

Usethefirstinstanceofthekeywefind

Submountmaps

Useanothermaptodefinethecontentsofthismountpoint Canbethoughtofasamastermap specifiedviathefstypemountoption

auto.master: /lanhosts /etc/auto.lanhosts

/etc/auto.lanhosts: server1 fstype=autofs server2fstype=autofs auto.server1: foo bar baz server1:/export/foo server1:/export/bar server1:/export/share/baz file:auto.server1 file:auto.server2

SubmountMaps(cont'd)
/lanhosts<fstype=autofs /server1<fstype=autofs /foo<fstype=nfs /bar /baz /server2<fstype=autofs #mount|greplanhosts automount(pid10523)on/lanhoststypeautofs (rw,fd=5,pgrp=10523,minproto=2,maxproto=4) automount(pid10532)on/lanhosts/server1typeautofs (rw,fd=5,pgrp=10523,minproto=2,maxproto=4) server1:/export/fooon/lanhosts/server1/footypenfs(rw) ...

Autofsv4DirectMaps

Implementedassubmountmaps

foreachelementofthepath,asubmountisdefined thetoplevelpathcomponentwillbeovermountedbyanautofsfilesystem asaresultoftheabove,youcannothaveatopleveldirectmount

2keyproblemswiththis

Autofs4DirectMapExample
auto.direct: /nfs/os/linux/usr /nfs/os/linux/bin /nfs/os/linux/local /nfs2/foo /nfs<fstype=autofs /os<fstype=autofs /linux<fstype=autofs /usr<fstype=nfs /bin<fstype=nfs /local<fstype=nfs /nfs2<fstype=autofs /foo<fstype=nfs linuxserver:/export/usr linuxserver:/export/bin linuxserver:/export/local fileserver:/export/foo

Autofs4DirectMapExample(cont'd)
automount(pid13258)on/nfstypeautofs (rw,fd=4,pgrp=13252,minproto=2,maxproto=4) automount(pid13262)on/nfs2typeautofs (rw,fd=4,pgrp=13252,minproto=2,maxproto=4) automount(pid13270)on/nfs/ostypeautofs (rw,fd=4,pgrp=13252,minproto=2,maxproto=4) automount(pid13276)on/nfs/os/linuxtypeautofs (rw,fd=4,pgrp=13252,minproto=2,maxproto=4) root132520.00.21808720?Ss12:100:00 /usr/sbin/automounttimeout=60/file/etc/auto.direct root132580.00.21808736?S12:100:00 /usr/sbin/automountsubmounttimeout=60/nfsfile/etc/auto.direct root132620.00.21808728?S12:100:00 /usr/sbin/automountsubmounttimeout=60/nfs2file/etc/auto.direct root132980.00.21812736?S12:120:00 /usr/sbin/automountsubmounttimeout=60/nfs/osfile/etc/auto.direct root133070.00.21808728?S12:120:00 /usr/sbin/automountsubmounttimeout=60/nfs/os/linuxfile /etc/auto.direct

AutomountArchitecture

UserspaceDaemon

parsemaps createautomountdirectories performmountsandunmounts triggerringexpiryofmounts trapfilesystemaccesstoautomountowneddirectories providedaemonwithinformationonmountpointusage

Autofsfilesystem

AutomountLoadableModules

Loadablemodules

lookup

daemonproper moduleframework lookupmodule parsemodule mountmodule

files,nis,nisplus sun,hesiod autofs,generic,nfs,etc.

parse

mount

AutofsLoadableModules

Benefits

Easytomaintainoutoftreemodules Introducesartificialseparation specifically,causesproblemsforincludedmaps

Drawbacks

Autofs4FileSystem

Virtualfilesystem Registertriggersfor

readdir lookup d_revalidate

MountDiagram

ExpiryDiagram

AutofsInherentRaceConditions

Expiry

ioctl(IOC_EXPIRE_MULTI) kernelcheckstheusecountofadirectoryhierarchy itchecksoutokay,sowetellthedaemontogoaheadandexpirethetree anapplicationtraversesintothedirectoryhierarchywearetryingtoexpire theunmountfails Notreally.

Isthisabigdeal?

Autofs5

Goal:100%compatibility Bigticketitems

Directmapsupport lazymountandunmountofmultimountmaps Utilizethenameserviceswitch Includedmaps

Autofs5DirectMaps

Needtoinstallhooksinthefilesystemwhichtriggeranautomount,without mountinganautofsfilesystem

filesystemstackingwasconsideredtobetoocomplex Hackeryensues...
>follow_linkisneverfilledinforadirectoryinode,wecanusethat!

Settingupadirectmounttriggernowlookslikethis:

Createtherequireddirectoryinthehierarchy

thedirectorycanexistonthehostfilesystem,onannfsmountedfile system,cifs,etc. Thisroutinenowiscalled(fromlink_path_walk)whenaprogram accessesthedirectory

Installourownfollow_linkroutine

Autofs5DirectMaps(cont'd)

Usingthismethod,wenowonlyneed1daemonforalldirectmounts Updatesandremovalsfromthemapareprocessedautomatically,butnot additions

Autofs5Lazymount/unmount

Turnsoutwecanleveragethedirctmapworkforthis,too Stillcreateourautofsdirectoryhierarchy,butnowdon'tmounteverythingat once. Triggersareinstalledintheappropriatetopleveldirectories,andaremounted uponaccess

Autofs5Features(cont'd)

Utilizethenameserviceswitch

mastermap submountmaps Needtoeitherwriteaparserforthensswitch.conffileformat,orimplementa nssmoduleforautomount


automount:nis[NOTFOUND=return]ldap

Supportincludedmaps

detectrecursion integrationofmodules

Summary

Added

extendedtosupportmultimapentries(nottobeconfusedwithmultimount entries) /etc/nsswitch.confisnotcurrentlyconsulted nullmapnotsupported Includedmapsarenotsupported Directmaps browseisnotthedefault,andiscalledghostinLinux hostsmapsareimplementedasmultimountmaps

Missing

Different

lazymountingandunmountingisnotimplemented

Contributing

MasterMapUtility

getridofmostoftheinitscript maybeevenreplacetheentireparser mountwithproperuid/gid authentication currentlyonlysupportsanonymousaccess

CIFS!

LDAP

Interactionwithnewbindmountsemantics(orold) Realreplicatedserversupport

changestomount,nfsclientcode,minimalchangestoautofs

Bugwhacking Testing

MoreInformation

autofsmailinglist

autofs@linux.kernel.org http://people.redhat.com/jmoyer/ ftp://ftp.kernel.org/pub/linux/kernel/people/raven/

mypeoplepage

officialautofsdistribution

RelatedProjects

autofsng amd autodir

References
[1]LinuxKernelsource,Version2.4and2.6,http://www.kernel.org/. [2]HalStern,MikeEislerandRichardoLabiaga,ManagingNFSandNIS,2nd Edition,O'Reilly,June2001 [3]W.RichardStevens,BillFenner,andAndrewM.Rudoff,UNIXNetwork Programming,TheSocketsNetworkingAPI,Volume1,ThirdEdition, AddisonWesleyProfessionalComputingPress,2004. [4]TravisBar,NicolaiLangfeldt,SethVidalandTomMcNeal,LinuxNFSHOWTO, http://nfs.sourceforge.net/nfshowto/,20020825. [5]FiST:StackableFileSystemLanguageandTemplates,ErazZadoketal., http://www.filesystems.org/. [6]SunTMMicrosystemsNFSAdministrationGuide,Chapter5,http://docs.sun.com/, 1995. [7]RobertLove,LinuxKernelDevelopment,SecondEdition,NovellPress,2005.

Das könnte Ihnen auch gefallen