super.c 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * super.c
  5. *
  6. * load/unload driver, mount/dismount volumes
  7. *
  8. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/fs.h>
  27. #include <linux/types.h>
  28. #include <linux/slab.h>
  29. #include <linux/highmem.h>
  30. #include <linux/init.h>
  31. #include <linux/random.h>
  32. #include <linux/statfs.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/blkdev.h>
  35. #include <linux/socket.h>
  36. #include <linux/inet.h>
  37. #include <linux/parser.h>
  38. #include <linux/crc32.h>
  39. #include <linux/debugfs.h>
  40. #include <linux/mount.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/quotaops.h>
  43. #define MLOG_MASK_PREFIX ML_SUPER
  44. #include <cluster/masklog.h>
  45. #include "ocfs2.h"
  46. /* this should be the only file to include a version 1 header */
  47. #include "ocfs1_fs_compat.h"
  48. #include "alloc.h"
  49. #include "blockcheck.h"
  50. #include "dlmglue.h"
  51. #include "export.h"
  52. #include "extent_map.h"
  53. #include "heartbeat.h"
  54. #include "inode.h"
  55. #include "journal.h"
  56. #include "localalloc.h"
  57. #include "namei.h"
  58. #include "slot_map.h"
  59. #include "super.h"
  60. #include "sysfile.h"
  61. #include "uptodate.h"
  62. #include "ver.h"
  63. #include "xattr.h"
  64. #include "quota.h"
  65. #include "refcounttree.h"
  66. #include "suballoc.h"
  67. #include "buffer_head_io.h"
  68. static struct kmem_cache *ocfs2_inode_cachep = NULL;
  69. struct kmem_cache *ocfs2_dquot_cachep;
  70. struct kmem_cache *ocfs2_qf_chunk_cachep;
  71. /* OCFS2 needs to schedule several differnt types of work which
  72. * require cluster locking, disk I/O, recovery waits, etc. Since these
  73. * types of work tend to be heavy we avoid using the kernel events
  74. * workqueue and schedule on our own. */
  75. struct workqueue_struct *ocfs2_wq = NULL;
  76. static struct dentry *ocfs2_debugfs_root = NULL;
  77. MODULE_AUTHOR("Oracle");
  78. MODULE_LICENSE("GPL");
  79. struct mount_options
  80. {
  81. unsigned long commit_interval;
  82. unsigned long mount_opt;
  83. unsigned int atime_quantum;
  84. signed short slot;
  85. int localalloc_opt;
  86. unsigned int resv_level;
  87. int dir_resv_level;
  88. char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
  89. };
  90. static int ocfs2_parse_options(struct super_block *sb, char *options,
  91. struct mount_options *mopt,
  92. int is_remount);
  93. static int ocfs2_check_set_options(struct super_block *sb,
  94. struct mount_options *options);
  95. static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
  96. static void ocfs2_put_super(struct super_block *sb);
  97. static int ocfs2_mount_volume(struct super_block *sb);
  98. static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
  99. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
  100. static int ocfs2_initialize_mem_caches(void);
  101. static void ocfs2_free_mem_caches(void);
  102. static void ocfs2_delete_osb(struct ocfs2_super *osb);
  103. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
  104. static int ocfs2_sync_fs(struct super_block *sb, int wait);
  105. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
  106. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
  107. static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
  108. static int ocfs2_check_volume(struct ocfs2_super *osb);
  109. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  110. struct buffer_head *bh,
  111. u32 sectsize,
  112. struct ocfs2_blockcheck_stats *stats);
  113. static int ocfs2_initialize_super(struct super_block *sb,
  114. struct buffer_head *bh,
  115. int sector_size,
  116. struct ocfs2_blockcheck_stats *stats);
  117. static int ocfs2_get_sector(struct super_block *sb,
  118. struct buffer_head **bh,
  119. int block,
  120. int sect_size);
  121. static struct inode *ocfs2_alloc_inode(struct super_block *sb);
  122. static void ocfs2_destroy_inode(struct inode *inode);
  123. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
  124. static int ocfs2_enable_quotas(struct ocfs2_super *osb);
  125. static void ocfs2_disable_quotas(struct ocfs2_super *osb);
  126. static const struct super_operations ocfs2_sops = {
  127. .statfs = ocfs2_statfs,
  128. .alloc_inode = ocfs2_alloc_inode,
  129. .destroy_inode = ocfs2_destroy_inode,
  130. .drop_inode = ocfs2_drop_inode,
  131. .evict_inode = ocfs2_evict_inode,
  132. .sync_fs = ocfs2_sync_fs,
  133. .put_super = ocfs2_put_super,
  134. .remount_fs = ocfs2_remount,
  135. .show_options = ocfs2_show_options,
  136. .quota_read = ocfs2_quota_read,
  137. .quota_write = ocfs2_quota_write,
  138. };
  139. enum {
  140. Opt_barrier,
  141. Opt_err_panic,
  142. Opt_err_ro,
  143. Opt_intr,
  144. Opt_nointr,
  145. Opt_hb_none,
  146. Opt_hb_local,
  147. Opt_hb_global,
  148. Opt_data_ordered,
  149. Opt_data_writeback,
  150. Opt_atime_quantum,
  151. Opt_slot,
  152. Opt_commit,
  153. Opt_localalloc,
  154. Opt_localflocks,
  155. Opt_stack,
  156. Opt_user_xattr,
  157. Opt_nouser_xattr,
  158. Opt_inode64,
  159. Opt_acl,
  160. Opt_noacl,
  161. Opt_usrquota,
  162. Opt_grpquota,
  163. Opt_coherency_buffered,
  164. Opt_coherency_full,
  165. Opt_resv_level,
  166. Opt_dir_resv_level,
  167. Opt_err,
  168. };
  169. static const match_table_t tokens = {
  170. {Opt_barrier, "barrier=%u"},
  171. {Opt_err_panic, "errors=panic"},
  172. {Opt_err_ro, "errors=remount-ro"},
  173. {Opt_intr, "intr"},
  174. {Opt_nointr, "nointr"},
  175. {Opt_hb_none, OCFS2_HB_NONE},
  176. {Opt_hb_local, OCFS2_HB_LOCAL},
  177. {Opt_hb_global, OCFS2_HB_GLOBAL},
  178. {Opt_data_ordered, "data=ordered"},
  179. {Opt_data_writeback, "data=writeback"},
  180. {Opt_atime_quantum, "atime_quantum=%u"},
  181. {Opt_slot, "preferred_slot=%u"},
  182. {Opt_commit, "commit=%u"},
  183. {Opt_localalloc, "localalloc=%d"},
  184. {Opt_localflocks, "localflocks"},
  185. {Opt_stack, "cluster_stack=%s"},
  186. {Opt_user_xattr, "user_xattr"},
  187. {Opt_nouser_xattr, "nouser_xattr"},
  188. {Opt_inode64, "inode64"},
  189. {Opt_acl, "acl"},
  190. {Opt_noacl, "noacl"},
  191. {Opt_usrquota, "usrquota"},
  192. {Opt_grpquota, "grpquota"},
  193. {Opt_coherency_buffered, "coherency=buffered"},
  194. {Opt_coherency_full, "coherency=full"},
  195. {Opt_resv_level, "resv_level=%u"},
  196. {Opt_dir_resv_level, "dir_resv_level=%u"},
  197. {Opt_err, NULL}
  198. };
  199. #ifdef CONFIG_DEBUG_FS
  200. static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
  201. {
  202. struct ocfs2_cluster_connection *cconn = osb->cconn;
  203. struct ocfs2_recovery_map *rm = osb->recovery_map;
  204. struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
  205. int i, out = 0;
  206. out += snprintf(buf + out, len - out,
  207. "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
  208. "Device", osb->dev_str, osb->uuid_str,
  209. osb->fs_generation, osb->vol_label);
  210. out += snprintf(buf + out, len - out,
  211. "%10s => State: %d Flags: 0x%lX\n", "Volume",
  212. atomic_read(&osb->vol_state), osb->osb_flags);
  213. out += snprintf(buf + out, len - out,
  214. "%10s => Block: %lu Cluster: %d\n", "Sizes",
  215. osb->sb->s_blocksize, osb->s_clustersize);
  216. out += snprintf(buf + out, len - out,
  217. "%10s => Compat: 0x%X Incompat: 0x%X "
  218. "ROcompat: 0x%X\n",
  219. "Features", osb->s_feature_compat,
  220. osb->s_feature_incompat, osb->s_feature_ro_compat);
  221. out += snprintf(buf + out, len - out,
  222. "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
  223. osb->s_mount_opt, osb->s_atime_quantum);
  224. if (cconn) {
  225. out += snprintf(buf + out, len - out,
  226. "%10s => Stack: %s Name: %*s "
  227. "Version: %d.%d\n", "Cluster",
  228. (*osb->osb_cluster_stack == '\0' ?
  229. "o2cb" : osb->osb_cluster_stack),
  230. cconn->cc_namelen, cconn->cc_name,
  231. cconn->cc_version.pv_major,
  232. cconn->cc_version.pv_minor);
  233. }
  234. spin_lock(&osb->dc_task_lock);
  235. out += snprintf(buf + out, len - out,
  236. "%10s => Pid: %d Count: %lu WakeSeq: %lu "
  237. "WorkSeq: %lu\n", "DownCnvt",
  238. (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
  239. osb->blocked_lock_count, osb->dc_wake_sequence,
  240. osb->dc_work_sequence);
  241. spin_unlock(&osb->dc_task_lock);
  242. spin_lock(&osb->osb_lock);
  243. out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
  244. "Recovery",
  245. (osb->recovery_thread_task ?
  246. task_pid_nr(osb->recovery_thread_task) : -1));
  247. if (rm->rm_used == 0)
  248. out += snprintf(buf + out, len - out, " None\n");
  249. else {
  250. for (i = 0; i < rm->rm_used; i++)
  251. out += snprintf(buf + out, len - out, " %d",
  252. rm->rm_entries[i]);
  253. out += snprintf(buf + out, len - out, "\n");
  254. }
  255. spin_unlock(&osb->osb_lock);
  256. out += snprintf(buf + out, len - out,
  257. "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
  258. (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
  259. osb->osb_commit_interval,
  260. atomic_read(&osb->needs_checkpoint));
  261. out += snprintf(buf + out, len - out,
  262. "%10s => State: %d TxnId: %lu NumTxns: %d\n",
  263. "Journal", osb->journal->j_state,
  264. osb->journal->j_trans_id,
  265. atomic_read(&osb->journal->j_num_trans));
  266. out += snprintf(buf + out, len - out,
  267. "%10s => GlobalAllocs: %d LocalAllocs: %d "
  268. "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
  269. "Stats",
  270. atomic_read(&osb->alloc_stats.bitmap_data),
  271. atomic_read(&osb->alloc_stats.local_data),
  272. atomic_read(&osb->alloc_stats.bg_allocs),
  273. atomic_read(&osb->alloc_stats.moves),
  274. atomic_read(&osb->alloc_stats.bg_extends));
  275. out += snprintf(buf + out, len - out,
  276. "%10s => State: %u Descriptor: %llu Size: %u bits "
  277. "Default: %u bits\n",
  278. "LocalAlloc", osb->local_alloc_state,
  279. (unsigned long long)osb->la_last_gd,
  280. osb->local_alloc_bits, osb->local_alloc_default_bits);
  281. spin_lock(&osb->osb_lock);
  282. out += snprintf(buf + out, len - out,
  283. "%10s => InodeSlot: %d StolenInodes: %d, "
  284. "MetaSlot: %d StolenMeta: %d\n", "Steal",
  285. osb->s_inode_steal_slot,
  286. atomic_read(&osb->s_num_inodes_stolen),
  287. osb->s_meta_steal_slot,
  288. atomic_read(&osb->s_num_meta_stolen));
  289. spin_unlock(&osb->osb_lock);
  290. out += snprintf(buf + out, len - out, "OrphanScan => ");
  291. out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
  292. os->os_count, os->os_seqno);
  293. out += snprintf(buf + out, len - out, " Last Scan: ");
  294. if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
  295. out += snprintf(buf + out, len - out, "Disabled\n");
  296. else
  297. out += snprintf(buf + out, len - out, "%lu seconds ago\n",
  298. (get_seconds() - os->os_scantime.tv_sec));
  299. out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
  300. "Slots", "Num", "RecoGen");
  301. for (i = 0; i < osb->max_slots; ++i) {
  302. out += snprintf(buf + out, len - out,
  303. "%10s %c %3d %10d\n",
  304. " ",
  305. (i == osb->slot_num ? '*' : ' '),
  306. i, osb->slot_recovery_generations[i]);
  307. }
  308. return out;
  309. }
  310. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  311. {
  312. struct ocfs2_super *osb = inode->i_private;
  313. char *buf = NULL;
  314. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  315. if (!buf)
  316. goto bail;
  317. i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
  318. file->private_data = buf;
  319. return 0;
  320. bail:
  321. return -ENOMEM;
  322. }
  323. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  324. {
  325. kfree(file->private_data);
  326. return 0;
  327. }
  328. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  329. size_t nbytes, loff_t *ppos)
  330. {
  331. return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
  332. i_size_read(file->f_mapping->host));
  333. }
  334. #else
  335. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  336. {
  337. return 0;
  338. }
  339. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  340. {
  341. return 0;
  342. }
  343. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  344. size_t nbytes, loff_t *ppos)
  345. {
  346. return 0;
  347. }
  348. #endif /* CONFIG_DEBUG_FS */
  349. static const struct file_operations ocfs2_osb_debug_fops = {
  350. .open = ocfs2_osb_debug_open,
  351. .release = ocfs2_debug_release,
  352. .read = ocfs2_debug_read,
  353. .llseek = generic_file_llseek,
  354. };
  355. static int ocfs2_sync_fs(struct super_block *sb, int wait)
  356. {
  357. int status;
  358. tid_t target;
  359. struct ocfs2_super *osb = OCFS2_SB(sb);
  360. if (ocfs2_is_hard_readonly(osb))
  361. return -EROFS;
  362. if (wait) {
  363. status = ocfs2_flush_truncate_log(osb);
  364. if (status < 0)
  365. mlog_errno(status);
  366. } else {
  367. ocfs2_schedule_truncate_log_flush(osb, 0);
  368. }
  369. if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
  370. &target)) {
  371. if (wait)
  372. jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
  373. target);
  374. }
  375. return 0;
  376. }
  377. static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
  378. {
  379. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
  380. && (ino == USER_QUOTA_SYSTEM_INODE
  381. || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
  382. return 0;
  383. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
  384. && (ino == GROUP_QUOTA_SYSTEM_INODE
  385. || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
  386. return 0;
  387. return 1;
  388. }
  389. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
  390. {
  391. struct inode *new = NULL;
  392. int status = 0;
  393. int i;
  394. mlog_entry_void();
  395. new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  396. if (IS_ERR(new)) {
  397. status = PTR_ERR(new);
  398. mlog_errno(status);
  399. goto bail;
  400. }
  401. osb->root_inode = new;
  402. new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  403. if (IS_ERR(new)) {
  404. status = PTR_ERR(new);
  405. mlog_errno(status);
  406. goto bail;
  407. }
  408. osb->sys_root_inode = new;
  409. for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
  410. i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
  411. if (!ocfs2_need_system_inode(osb, i))
  412. continue;
  413. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  414. if (!new) {
  415. ocfs2_release_system_inodes(osb);
  416. status = -EINVAL;
  417. mlog_errno(status);
  418. /* FIXME: Should ERROR_RO_FS */
  419. mlog(ML_ERROR, "Unable to load system inode %d, "
  420. "possibly corrupt fs?", i);
  421. goto bail;
  422. }
  423. // the array now has one ref, so drop this one
  424. iput(new);
  425. }
  426. bail:
  427. mlog_exit(status);
  428. return status;
  429. }
  430. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
  431. {
  432. struct inode *new = NULL;
  433. int status = 0;
  434. int i;
  435. mlog_entry_void();
  436. for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
  437. i < NUM_SYSTEM_INODES;
  438. i++) {
  439. if (!ocfs2_need_system_inode(osb, i))
  440. continue;
  441. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  442. if (!new) {
  443. ocfs2_release_system_inodes(osb);
  444. status = -EINVAL;
  445. mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
  446. status, i, osb->slot_num);
  447. goto bail;
  448. }
  449. /* the array now has one ref, so drop this one */
  450. iput(new);
  451. }
  452. bail:
  453. mlog_exit(status);
  454. return status;
  455. }
  456. static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
  457. {
  458. int i;
  459. struct inode *inode;
  460. mlog_entry_void();
  461. for (i = 0; i < NUM_GLOBAL_SYSTEM_INODES; i++) {
  462. inode = osb->global_system_inodes[i];
  463. if (inode) {
  464. iput(inode);
  465. osb->global_system_inodes[i] = NULL;
  466. }
  467. }
  468. inode = osb->sys_root_inode;
  469. if (inode) {
  470. iput(inode);
  471. osb->sys_root_inode = NULL;
  472. }
  473. inode = osb->root_inode;
  474. if (inode) {
  475. iput(inode);
  476. osb->root_inode = NULL;
  477. }
  478. if (!osb->local_system_inodes)
  479. goto out;
  480. for (i = 0; i < NUM_LOCAL_SYSTEM_INODES * osb->max_slots; i++) {
  481. if (osb->local_system_inodes[i]) {
  482. iput(osb->local_system_inodes[i]);
  483. osb->local_system_inodes[i] = NULL;
  484. }
  485. }
  486. kfree(osb->local_system_inodes);
  487. osb->local_system_inodes = NULL;
  488. out:
  489. mlog_exit(0);
  490. }
  491. /* We're allocating fs objects, use GFP_NOFS */
  492. static struct inode *ocfs2_alloc_inode(struct super_block *sb)
  493. {
  494. struct ocfs2_inode_info *oi;
  495. oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
  496. if (!oi)
  497. return NULL;
  498. jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
  499. return &oi->vfs_inode;
  500. }
  501. static void ocfs2_i_callback(struct rcu_head *head)
  502. {
  503. struct inode *inode = container_of(head, struct inode, i_rcu);
  504. INIT_LIST_HEAD(&inode->i_dentry);
  505. kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
  506. }
  507. static void ocfs2_destroy_inode(struct inode *inode)
  508. {
  509. call_rcu(&inode->i_rcu, ocfs2_i_callback);
  510. }
  511. static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
  512. unsigned int cbits)
  513. {
  514. unsigned int bytes = 1 << cbits;
  515. unsigned int trim = bytes;
  516. unsigned int bitshift = 32;
  517. /*
  518. * i_size and all block offsets in ocfs2 are always 64 bits
  519. * wide. i_clusters is 32 bits, in cluster-sized units. So on
  520. * 64 bit platforms, cluster size will be the limiting factor.
  521. */
  522. #if BITS_PER_LONG == 32
  523. # if defined(CONFIG_LBDAF)
  524. BUILD_BUG_ON(sizeof(sector_t) != 8);
  525. /*
  526. * We might be limited by page cache size.
  527. */
  528. if (bytes > PAGE_CACHE_SIZE) {
  529. bytes = PAGE_CACHE_SIZE;
  530. trim = 1;
  531. /*
  532. * Shift by 31 here so that we don't get larger than
  533. * MAX_LFS_FILESIZE
  534. */
  535. bitshift = 31;
  536. }
  537. # else
  538. /*
  539. * We are limited by the size of sector_t. Use block size, as
  540. * that's what we expose to the VFS.
  541. */
  542. bytes = 1 << bbits;
  543. trim = 1;
  544. bitshift = 31;
  545. # endif
  546. #endif
  547. /*
  548. * Trim by a whole cluster when we can actually approach the
  549. * on-disk limits. Otherwise we can overflow i_clusters when
  550. * an extent start is at the max offset.
  551. */
  552. return (((unsigned long long)bytes) << bitshift) - trim;
  553. }
  554. static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
  555. {
  556. int incompat_features;
  557. int ret = 0;
  558. struct mount_options parsed_options;
  559. struct ocfs2_super *osb = OCFS2_SB(sb);
  560. u32 tmp;
  561. if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
  562. !ocfs2_check_set_options(sb, &parsed_options)) {
  563. ret = -EINVAL;
  564. goto out;
  565. }
  566. tmp = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL |
  567. OCFS2_MOUNT_HB_NONE;
  568. if ((osb->s_mount_opt & tmp) != (parsed_options.mount_opt & tmp)) {
  569. ret = -EINVAL;
  570. mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
  571. goto out;
  572. }
  573. if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
  574. (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
  575. ret = -EINVAL;
  576. mlog(ML_ERROR, "Cannot change data mode on remount\n");
  577. goto out;
  578. }
  579. /* Probably don't want this on remount; it might
  580. * mess with other nodes */
  581. if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
  582. (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
  583. ret = -EINVAL;
  584. mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
  585. goto out;
  586. }
  587. /* We're going to/from readonly mode. */
  588. if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
  589. /* Disable quota accounting before remounting RO */
  590. if (*flags & MS_RDONLY) {
  591. ret = ocfs2_susp_quotas(osb, 0);
  592. if (ret < 0)
  593. goto out;
  594. }
  595. /* Lock here so the check of HARD_RO and the potential
  596. * setting of SOFT_RO is atomic. */
  597. spin_lock(&osb->osb_lock);
  598. if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
  599. mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
  600. ret = -EROFS;
  601. goto unlock_osb;
  602. }
  603. if (*flags & MS_RDONLY) {
  604. mlog(0, "Going to ro mode.\n");
  605. sb->s_flags |= MS_RDONLY;
  606. osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  607. } else {
  608. mlog(0, "Making ro filesystem writeable.\n");
  609. if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
  610. mlog(ML_ERROR, "Cannot remount RDWR "
  611. "filesystem due to previous errors.\n");
  612. ret = -EROFS;
  613. goto unlock_osb;
  614. }
  615. incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
  616. if (incompat_features) {
  617. mlog(ML_ERROR, "Cannot remount RDWR because "
  618. "of unsupported optional features "
  619. "(%x).\n", incompat_features);
  620. ret = -EINVAL;
  621. goto unlock_osb;
  622. }
  623. sb->s_flags &= ~MS_RDONLY;
  624. osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
  625. }
  626. unlock_osb:
  627. spin_unlock(&osb->osb_lock);
  628. /* Enable quota accounting after remounting RW */
  629. if (!ret && !(*flags & MS_RDONLY)) {
  630. if (sb_any_quota_suspended(sb))
  631. ret = ocfs2_susp_quotas(osb, 1);
  632. else
  633. ret = ocfs2_enable_quotas(osb);
  634. if (ret < 0) {
  635. /* Return back changes... */
  636. spin_lock(&osb->osb_lock);
  637. sb->s_flags |= MS_RDONLY;
  638. osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  639. spin_unlock(&osb->osb_lock);
  640. goto out;
  641. }
  642. }
  643. }
  644. if (!ret) {
  645. /* Only save off the new mount options in case of a successful
  646. * remount. */
  647. osb->s_mount_opt = parsed_options.mount_opt;
  648. osb->s_atime_quantum = parsed_options.atime_quantum;
  649. osb->preferred_slot = parsed_options.slot;
  650. if (parsed_options.commit_interval)
  651. osb->osb_commit_interval = parsed_options.commit_interval;
  652. if (!ocfs2_is_hard_readonly(osb))
  653. ocfs2_set_journal_params(osb);
  654. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  655. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
  656. MS_POSIXACL : 0);
  657. }
  658. out:
  659. return ret;
  660. }
  661. static int ocfs2_sb_probe(struct super_block *sb,
  662. struct buffer_head **bh,
  663. int *sector_size,
  664. struct ocfs2_blockcheck_stats *stats)
  665. {
  666. int status, tmpstat;
  667. struct ocfs1_vol_disk_hdr *hdr;
  668. struct ocfs2_dinode *di;
  669. int blksize;
  670. *bh = NULL;
  671. /* may be > 512 */
  672. *sector_size = bdev_logical_block_size(sb->s_bdev);
  673. if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
  674. mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
  675. *sector_size, OCFS2_MAX_BLOCKSIZE);
  676. status = -EINVAL;
  677. goto bail;
  678. }
  679. /* Can this really happen? */
  680. if (*sector_size < OCFS2_MIN_BLOCKSIZE)
  681. *sector_size = OCFS2_MIN_BLOCKSIZE;
  682. /* check block zero for old format */
  683. status = ocfs2_get_sector(sb, bh, 0, *sector_size);
  684. if (status < 0) {
  685. mlog_errno(status);
  686. goto bail;
  687. }
  688. hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
  689. if (hdr->major_version == OCFS1_MAJOR_VERSION) {
  690. mlog(ML_ERROR, "incompatible version: %u.%u\n",
  691. hdr->major_version, hdr->minor_version);
  692. status = -EINVAL;
  693. }
  694. if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
  695. strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
  696. mlog(ML_ERROR, "incompatible volume signature: %8s\n",
  697. hdr->signature);
  698. status = -EINVAL;
  699. }
  700. brelse(*bh);
  701. *bh = NULL;
  702. if (status < 0) {
  703. mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
  704. "upgraded before mounting with ocfs v2\n");
  705. goto bail;
  706. }
  707. /*
  708. * Now check at magic offset for 512, 1024, 2048, 4096
  709. * blocksizes. 4096 is the maximum blocksize because it is
  710. * the minimum clustersize.
  711. */
  712. status = -EINVAL;
  713. for (blksize = *sector_size;
  714. blksize <= OCFS2_MAX_BLOCKSIZE;
  715. blksize <<= 1) {
  716. tmpstat = ocfs2_get_sector(sb, bh,
  717. OCFS2_SUPER_BLOCK_BLKNO,
  718. blksize);
  719. if (tmpstat < 0) {
  720. status = tmpstat;
  721. mlog_errno(status);
  722. break;
  723. }
  724. di = (struct ocfs2_dinode *) (*bh)->b_data;
  725. memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
  726. spin_lock_init(&stats->b_lock);
  727. tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
  728. if (tmpstat < 0) {
  729. brelse(*bh);
  730. *bh = NULL;
  731. }
  732. if (tmpstat != -EAGAIN) {
  733. status = tmpstat;
  734. break;
  735. }
  736. }
  737. bail:
  738. return status;
  739. }
  740. static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
  741. {
  742. u32 hb_enabled = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL;
  743. if (osb->s_mount_opt & hb_enabled) {
  744. if (ocfs2_mount_local(osb)) {
  745. mlog(ML_ERROR, "Cannot heartbeat on a locally "
  746. "mounted device.\n");
  747. return -EINVAL;
  748. }
  749. if (ocfs2_userspace_stack(osb)) {
  750. mlog(ML_ERROR, "Userspace stack expected, but "
  751. "o2cb heartbeat arguments passed to mount\n");
  752. return -EINVAL;
  753. }
  754. if (((osb->s_mount_opt & OCFS2_MOUNT_HB_GLOBAL) &&
  755. !ocfs2_cluster_o2cb_global_heartbeat(osb)) ||
  756. ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) &&
  757. ocfs2_cluster_o2cb_global_heartbeat(osb))) {
  758. mlog(ML_ERROR, "Mismatching o2cb heartbeat modes\n");
  759. return -EINVAL;
  760. }
  761. }
  762. if (!(osb->s_mount_opt & hb_enabled)) {
  763. if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
  764. !ocfs2_userspace_stack(osb)) {
  765. mlog(ML_ERROR, "Heartbeat has to be started to mount "
  766. "a read-write clustered device.\n");
  767. return -EINVAL;
  768. }
  769. }
  770. return 0;
  771. }
  772. /*
  773. * If we're using a userspace stack, mount should have passed
  774. * a name that matches the disk. If not, mount should not
  775. * have passed a stack.
  776. */
  777. static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
  778. struct mount_options *mopt)
  779. {
  780. if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
  781. mlog(ML_ERROR,
  782. "cluster stack passed to mount, but this filesystem "
  783. "does not support it\n");
  784. return -EINVAL;
  785. }
  786. if (ocfs2_userspace_stack(osb) &&
  787. strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
  788. OCFS2_STACK_LABEL_LEN)) {
  789. mlog(ML_ERROR,
  790. "cluster stack passed to mount (\"%s\") does not "
  791. "match the filesystem (\"%s\")\n",
  792. mopt->cluster_stack,
  793. osb->osb_cluster_stack);
  794. return -EINVAL;
  795. }
  796. return 0;
  797. }
  798. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
  799. {
  800. int type;
  801. struct super_block *sb = osb->sb;
  802. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  803. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  804. int status = 0;
  805. for (type = 0; type < MAXQUOTAS; type++) {
  806. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  807. continue;
  808. if (unsuspend)
  809. status = dquot_resume(sb, type);
  810. else {
  811. struct ocfs2_mem_dqinfo *oinfo;
  812. /* Cancel periodic syncing before suspending */
  813. oinfo = sb_dqinfo(sb, type)->dqi_priv;
  814. cancel_delayed_work_sync(&oinfo->dqi_sync_work);
  815. status = dquot_suspend(sb, type);
  816. }
  817. if (status < 0)
  818. break;
  819. }
  820. if (status < 0)
  821. mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
  822. "remount (error = %d).\n", status);
  823. return status;
  824. }
  825. static int ocfs2_enable_quotas(struct ocfs2_super *osb)
  826. {
  827. struct inode *inode[MAXQUOTAS] = { NULL, NULL };
  828. struct super_block *sb = osb->sb;
  829. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  830. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  831. unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
  832. LOCAL_GROUP_QUOTA_SYSTEM_INODE };
  833. int status;
  834. int type;
  835. sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
  836. for (type = 0; type < MAXQUOTAS; type++) {
  837. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  838. continue;
  839. inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
  840. osb->slot_num);
  841. if (!inode[type]) {
  842. status = -ENOENT;
  843. goto out_quota_off;
  844. }
  845. status = dquot_enable(inode[type], type, QFMT_OCFS2,
  846. DQUOT_USAGE_ENABLED);
  847. if (status < 0)
  848. goto out_quota_off;
  849. }
  850. for (type = 0; type < MAXQUOTAS; type++)
  851. iput(inode[type]);
  852. return 0;
  853. out_quota_off:
  854. ocfs2_disable_quotas(osb);
  855. for (type = 0; type < MAXQUOTAS; type++)
  856. iput(inode[type]);
  857. mlog_errno(status);
  858. return status;
  859. }
  860. static void ocfs2_disable_quotas(struct ocfs2_super *osb)
  861. {
  862. int type;
  863. struct inode *inode;
  864. struct super_block *sb = osb->sb;
  865. struct ocfs2_mem_dqinfo *oinfo;
  866. /* We mostly ignore errors in this function because there's not much
  867. * we can do when we see them */
  868. for (type = 0; type < MAXQUOTAS; type++) {
  869. if (!sb_has_quota_loaded(sb, type))
  870. continue;
  871. /* Cancel periodic syncing before we grab dqonoff_mutex */
  872. oinfo = sb_dqinfo(sb, type)->dqi_priv;
  873. cancel_delayed_work_sync(&oinfo->dqi_sync_work);
  874. inode = igrab(sb->s_dquot.files[type]);
  875. /* Turn off quotas. This will remove all dquot structures from
  876. * memory and so they will be automatically synced to global
  877. * quota files */
  878. dquot_disable(sb, type, DQUOT_USAGE_ENABLED |
  879. DQUOT_LIMITS_ENABLED);
  880. if (!inode)
  881. continue;
  882. iput(inode);
  883. }
  884. }
  885. /* Handle quota on quotactl */
  886. static int ocfs2_quota_on(struct super_block *sb, int type, int format_id)
  887. {
  888. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  889. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  890. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  891. return -EINVAL;
  892. return dquot_enable(sb_dqopt(sb)->files[type], type,
  893. format_id, DQUOT_LIMITS_ENABLED);
  894. }
  895. /* Handle quota off quotactl */
  896. static int ocfs2_quota_off(struct super_block *sb, int type)
  897. {
  898. return dquot_disable(sb, type, DQUOT_LIMITS_ENABLED);
  899. }
  900. static const struct quotactl_ops ocfs2_quotactl_ops = {
  901. .quota_on_meta = ocfs2_quota_on,
  902. .quota_off = ocfs2_quota_off,
  903. .quota_sync = dquot_quota_sync,
  904. .get_info = dquot_get_dqinfo,
  905. .set_info = dquot_set_dqinfo,
  906. .get_dqblk = dquot_get_dqblk,
  907. .set_dqblk = dquot_set_dqblk,
  908. };
  909. static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
  910. {
  911. struct dentry *root;
  912. int status, sector_size;
  913. struct mount_options parsed_options;
  914. struct inode *inode = NULL;
  915. struct ocfs2_super *osb = NULL;
  916. struct buffer_head *bh = NULL;
  917. char nodestr[8];
  918. struct ocfs2_blockcheck_stats stats;
  919. mlog_entry("%p, %p, %i", sb, data, silent);
  920. if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
  921. status = -EINVAL;
  922. goto read_super_error;
  923. }
  924. /* probe for superblock */
  925. status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
  926. if (status < 0) {
  927. mlog(ML_ERROR, "superblock probe failed!\n");
  928. goto read_super_error;
  929. }
  930. status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
  931. osb = OCFS2_SB(sb);
  932. if (status < 0) {
  933. mlog_errno(status);
  934. goto read_super_error;
  935. }
  936. brelse(bh);
  937. bh = NULL;
  938. if (!ocfs2_check_set_options(sb, &parsed_options)) {
  939. status = -EINVAL;
  940. goto read_super_error;
  941. }
  942. osb->s_mount_opt = parsed_options.mount_opt;
  943. osb->s_atime_quantum = parsed_options.atime_quantum;
  944. osb->preferred_slot = parsed_options.slot;
  945. osb->osb_commit_interval = parsed_options.commit_interval;
  946. ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
  947. osb->osb_resv_level = parsed_options.resv_level;
  948. osb->osb_dir_resv_level = parsed_options.resv_level;
  949. if (parsed_options.dir_resv_level == -1)
  950. osb->osb_dir_resv_level = parsed_options.resv_level;
  951. else
  952. osb->osb_dir_resv_level = parsed_options.dir_resv_level;
  953. status = ocfs2_verify_userspace_stack(osb, &parsed_options);
  954. if (status)
  955. goto read_super_error;
  956. sb->s_magic = OCFS2_SUPER_MAGIC;
  957. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  958. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  959. /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
  960. * heartbeat=none */
  961. if (bdev_read_only(sb->s_bdev)) {
  962. if (!(sb->s_flags & MS_RDONLY)) {
  963. status = -EACCES;
  964. mlog(ML_ERROR, "Readonly device detected but readonly "
  965. "mount was not specified.\n");
  966. goto read_super_error;
  967. }
  968. /* You should not be able to start a local heartbeat
  969. * on a readonly device. */
  970. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  971. status = -EROFS;
  972. mlog(ML_ERROR, "Local heartbeat specified on readonly "
  973. "device.\n");
  974. goto read_super_error;
  975. }
  976. status = ocfs2_check_journals_nolocks(osb);
  977. if (status < 0) {
  978. if (status == -EROFS)
  979. mlog(ML_ERROR, "Recovery required on readonly "
  980. "file system, but write access is "
  981. "unavailable.\n");
  982. else
  983. mlog_errno(status);
  984. goto read_super_error;
  985. }
  986. ocfs2_set_ro_flag(osb, 1);
  987. printk(KERN_NOTICE "Readonly device detected. No cluster "
  988. "services will be utilized for this mount. Recovery "
  989. "will be skipped.\n");
  990. }
  991. if (!ocfs2_is_hard_readonly(osb)) {
  992. if (sb->s_flags & MS_RDONLY)
  993. ocfs2_set_ro_flag(osb, 0);
  994. }
  995. status = ocfs2_verify_heartbeat(osb);
  996. if (status < 0) {
  997. mlog_errno(status);
  998. goto read_super_error;
  999. }
  1000. osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
  1001. ocfs2_debugfs_root);
  1002. if (!osb->osb_debug_root) {
  1003. status = -EINVAL;
  1004. mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
  1005. goto read_super_error;
  1006. }
  1007. osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
  1008. osb->osb_debug_root,
  1009. osb,
  1010. &ocfs2_osb_debug_fops);
  1011. if (!osb->osb_ctxt) {
  1012. status = -EINVAL;
  1013. mlog_errno(status);
  1014. goto read_super_error;
  1015. }
  1016. if (ocfs2_meta_ecc(osb)) {
  1017. status = ocfs2_blockcheck_stats_debugfs_install(
  1018. &osb->osb_ecc_stats,
  1019. osb->osb_debug_root);
  1020. if (status) {
  1021. mlog(ML_ERROR,
  1022. "Unable to create blockcheck statistics "
  1023. "files\n");
  1024. goto read_super_error;
  1025. }
  1026. }
  1027. status = ocfs2_mount_volume(sb);
  1028. if (osb->root_inode)
  1029. inode = igrab(osb->root_inode);
  1030. if (status < 0)
  1031. goto read_super_error;
  1032. if (!inode) {
  1033. status = -EIO;
  1034. mlog_errno(status);
  1035. goto read_super_error;
  1036. }
  1037. root = d_alloc_root(inode);
  1038. if (!root) {
  1039. status = -ENOMEM;
  1040. mlog_errno(status);
  1041. goto read_super_error;
  1042. }
  1043. sb->s_root = root;
  1044. ocfs2_complete_mount_recovery(osb);
  1045. if (ocfs2_mount_local(osb))
  1046. snprintf(nodestr, sizeof(nodestr), "local");
  1047. else
  1048. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1049. printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
  1050. "with %s data mode.\n",
  1051. osb->dev_str, nodestr, osb->slot_num,
  1052. osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
  1053. "ordered");
  1054. atomic_set(&osb->vol_state, VOLUME_MOUNTED);
  1055. wake_up(&osb->osb_mount_event);
  1056. /* Now we can initialize quotas because we can afford to wait
  1057. * for cluster locks recovery now. That also means that truncation
  1058. * log recovery can happen but that waits for proper quota setup */
  1059. if (!(sb->s_flags & MS_RDONLY)) {
  1060. status = ocfs2_enable_quotas(osb);
  1061. if (status < 0) {
  1062. /* We have to err-out specially here because
  1063. * s_root is already set */
  1064. mlog_errno(status);
  1065. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1066. wake_up(&osb->osb_mount_event);
  1067. mlog_exit(status);
  1068. return status;
  1069. }
  1070. }
  1071. ocfs2_complete_quota_recovery(osb);
  1072. /* Now we wake up again for processes waiting for quotas */
  1073. atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
  1074. wake_up(&osb->osb_mount_event);
  1075. /* Start this when the mount is almost sure of being successful */
  1076. ocfs2_orphan_scan_start(osb);
  1077. mlog_exit(status);
  1078. return status;
  1079. read_super_error:
  1080. brelse(bh);
  1081. if (inode)
  1082. iput(inode);
  1083. if (osb) {
  1084. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1085. wake_up(&osb->osb_mount_event);
  1086. ocfs2_dismount_volume(sb, 1);
  1087. }
  1088. mlog_exit(status);
  1089. return status;
  1090. }
  1091. static struct dentry *ocfs2_mount(struct file_system_type *fs_type,
  1092. int flags,
  1093. const char *dev_name,
  1094. void *data)
  1095. {
  1096. return mount_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super);
  1097. }
  1098. static void ocfs2_kill_sb(struct super_block *sb)
  1099. {
  1100. struct ocfs2_super *osb = OCFS2_SB(sb);
  1101. /* Failed mount? */
  1102. if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
  1103. goto out;
  1104. /* Prevent further queueing of inode drop events */
  1105. spin_lock(&dentry_list_lock);
  1106. ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
  1107. spin_unlock(&dentry_list_lock);
  1108. /* Wait for work to finish and/or remove it */
  1109. cancel_work_sync(&osb->dentry_lock_work);
  1110. out:
  1111. kill_block_super(sb);
  1112. }
  1113. static struct file_system_type ocfs2_fs_type = {
  1114. .owner = THIS_MODULE,
  1115. .name = "ocfs2",
  1116. .mount = ocfs2_mount,
  1117. .kill_sb = ocfs2_kill_sb,
  1118. .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
  1119. .next = NULL
  1120. };
  1121. static int ocfs2_check_set_options(struct super_block *sb,
  1122. struct mount_options *options)
  1123. {
  1124. if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
  1125. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1126. OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
  1127. mlog(ML_ERROR, "User quotas were requested, but this "
  1128. "filesystem does not have the feature enabled.\n");
  1129. return 0;
  1130. }
  1131. if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
  1132. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1133. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
  1134. mlog(ML_ERROR, "Group quotas were requested, but this "
  1135. "filesystem does not have the feature enabled.\n");
  1136. return 0;
  1137. }
  1138. if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
  1139. !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
  1140. mlog(ML_ERROR, "ACL support requested but extended attributes "
  1141. "feature is not enabled\n");
  1142. return 0;
  1143. }
  1144. /* No ACL setting specified? Use XATTR feature... */
  1145. if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
  1146. OCFS2_MOUNT_NO_POSIX_ACL))) {
  1147. if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
  1148. options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1149. else
  1150. options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1151. }
  1152. return 1;
  1153. }
  1154. static int ocfs2_parse_options(struct super_block *sb,
  1155. char *options,
  1156. struct mount_options *mopt,
  1157. int is_remount)
  1158. {
  1159. int status, user_stack = 0;
  1160. char *p;
  1161. u32 tmp;
  1162. mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
  1163. options ? options : "(none)");
  1164. mopt->commit_interval = 0;
  1165. mopt->mount_opt = OCFS2_MOUNT_NOINTR;
  1166. mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1167. mopt->slot = OCFS2_INVALID_SLOT;
  1168. mopt->localalloc_opt = -1;
  1169. mopt->cluster_stack[0] = '\0';
  1170. mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
  1171. mopt->dir_resv_level = -1;
  1172. if (!options) {
  1173. status = 1;
  1174. goto bail;
  1175. }
  1176. while ((p = strsep(&options, ",")) != NULL) {
  1177. int token, option;
  1178. substring_t args[MAX_OPT_ARGS];
  1179. if (!*p)
  1180. continue;
  1181. token = match_token(p, tokens, args);
  1182. switch (token) {
  1183. case Opt_hb_local:
  1184. mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
  1185. break;
  1186. case Opt_hb_none:
  1187. mopt->mount_opt |= OCFS2_MOUNT_HB_NONE;
  1188. break;
  1189. case Opt_hb_global:
  1190. mopt->mount_opt |= OCFS2_MOUNT_HB_GLOBAL;
  1191. break;
  1192. case Opt_barrier:
  1193. if (match_int(&args[0], &option)) {
  1194. status = 0;
  1195. goto bail;
  1196. }
  1197. if (option)
  1198. mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
  1199. else
  1200. mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
  1201. break;
  1202. case Opt_intr:
  1203. mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
  1204. break;
  1205. case Opt_nointr:
  1206. mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
  1207. break;
  1208. case Opt_err_panic:
  1209. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  1210. break;
  1211. case Opt_err_ro:
  1212. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
  1213. break;
  1214. case Opt_data_ordered:
  1215. mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
  1216. break;
  1217. case Opt_data_writeback:
  1218. mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
  1219. break;
  1220. case Opt_user_xattr:
  1221. mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
  1222. break;
  1223. case Opt_nouser_xattr:
  1224. mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
  1225. break;
  1226. case Opt_atime_quantum:
  1227. if (match_int(&args[0], &option)) {
  1228. status = 0;
  1229. goto bail;
  1230. }
  1231. if (option >= 0)
  1232. mopt->atime_quantum = option;
  1233. break;
  1234. case Opt_slot:
  1235. option = 0;
  1236. if (match_int(&args[0], &option)) {
  1237. status = 0;
  1238. goto bail;
  1239. }
  1240. if (option)
  1241. mopt->slot = (s16)option;
  1242. break;
  1243. case Opt_commit:
  1244. option = 0;
  1245. if (match_int(&args[0], &option)) {
  1246. status = 0;
  1247. goto bail;
  1248. }
  1249. if (option < 0)
  1250. return 0;
  1251. if (option == 0)
  1252. option = JBD2_DEFAULT_MAX_COMMIT_AGE;
  1253. mopt->commit_interval = HZ * option;
  1254. break;
  1255. case Opt_localalloc:
  1256. option = 0;
  1257. if (match_int(&args[0], &option)) {
  1258. status = 0;
  1259. goto bail;
  1260. }
  1261. if (option >= 0)
  1262. mopt->localalloc_opt = option;
  1263. break;
  1264. case Opt_localflocks:
  1265. /*
  1266. * Changing this during remount could race
  1267. * flock() requests, or "unbalance" existing
  1268. * ones (e.g., a lock is taken in one mode but
  1269. * dropped in the other). If users care enough
  1270. * to flip locking modes during remount, we
  1271. * could add a "local" flag to individual
  1272. * flock structures for proper tracking of
  1273. * state.
  1274. */
  1275. if (!is_remount)
  1276. mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
  1277. break;
  1278. case Opt_stack:
  1279. /* Check both that the option we were passed
  1280. * is of the right length and that it is a proper
  1281. * string of the right length.
  1282. */
  1283. if (((args[0].to - args[0].from) !=
  1284. OCFS2_STACK_LABEL_LEN) ||
  1285. (strnlen(args[0].from,
  1286. OCFS2_STACK_LABEL_LEN) !=
  1287. OCFS2_STACK_LABEL_LEN)) {
  1288. mlog(ML_ERROR,
  1289. "Invalid cluster_stack option\n");
  1290. status = 0;
  1291. goto bail;
  1292. }
  1293. memcpy(mopt->cluster_stack, args[0].from,
  1294. OCFS2_STACK_LABEL_LEN);
  1295. mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1296. /*
  1297. * Open code the memcmp here as we don't have
  1298. * an osb to pass to
  1299. * ocfs2_userspace_stack().
  1300. */
  1301. if (memcmp(mopt->cluster_stack,
  1302. OCFS2_CLASSIC_CLUSTER_STACK,
  1303. OCFS2_STACK_LABEL_LEN))
  1304. user_stack = 1;
  1305. break;
  1306. case Opt_inode64:
  1307. mopt->mount_opt |= OCFS2_MOUNT_INODE64;
  1308. break;
  1309. case Opt_usrquota:
  1310. mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
  1311. break;
  1312. case Opt_grpquota:
  1313. mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
  1314. break;
  1315. case Opt_coherency_buffered:
  1316. mopt->mount_opt |= OCFS2_MOUNT_COHERENCY_BUFFERED;
  1317. break;
  1318. case Opt_coherency_full:
  1319. mopt->mount_opt &= ~OCFS2_MOUNT_COHERENCY_BUFFERED;
  1320. break;
  1321. case Opt_acl:
  1322. mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1323. mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
  1324. break;
  1325. case Opt_noacl:
  1326. mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1327. mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  1328. break;
  1329. case Opt_resv_level:
  1330. if (is_remount)
  1331. break;
  1332. if (match_int(&args[0], &option)) {
  1333. status = 0;
  1334. goto bail;
  1335. }
  1336. if (option >= OCFS2_MIN_RESV_LEVEL &&
  1337. option < OCFS2_MAX_RESV_LEVEL)
  1338. mopt->resv_level = option;
  1339. break;
  1340. case Opt_dir_resv_level:
  1341. if (is_remount)
  1342. break;
  1343. if (match_int(&args[0], &option)) {
  1344. status = 0;
  1345. goto bail;
  1346. }
  1347. if (option >= OCFS2_MIN_RESV_LEVEL &&
  1348. option < OCFS2_MAX_RESV_LEVEL)
  1349. mopt->dir_resv_level = option;
  1350. break;
  1351. default:
  1352. mlog(ML_ERROR,
  1353. "Unrecognized mount option \"%s\" "
  1354. "or missing value\n", p);
  1355. status = 0;
  1356. goto bail;
  1357. }
  1358. }
  1359. if (user_stack == 0) {
  1360. /* Ensure only one heartbeat mode */
  1361. tmp = mopt->mount_opt & (OCFS2_MOUNT_HB_LOCAL |
  1362. OCFS2_MOUNT_HB_GLOBAL |
  1363. OCFS2_MOUNT_HB_NONE);
  1364. if (hweight32(tmp) != 1) {
  1365. mlog(ML_ERROR, "Invalid heartbeat mount options\n");
  1366. status = 0;
  1367. goto bail;
  1368. }
  1369. }
  1370. status = 1;
  1371. bail:
  1372. mlog_exit(status);
  1373. return status;
  1374. }
  1375. static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  1376. {
  1377. struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
  1378. unsigned long opts = osb->s_mount_opt;
  1379. unsigned int local_alloc_megs;
  1380. if (opts & (OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL)) {
  1381. seq_printf(s, ",_netdev");
  1382. if (opts & OCFS2_MOUNT_HB_LOCAL)
  1383. seq_printf(s, ",%s", OCFS2_HB_LOCAL);
  1384. else
  1385. seq_printf(s, ",%s", OCFS2_HB_GLOBAL);
  1386. } else
  1387. seq_printf(s, ",%s", OCFS2_HB_NONE);
  1388. if (opts & OCFS2_MOUNT_NOINTR)
  1389. seq_printf(s, ",nointr");
  1390. if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
  1391. seq_printf(s, ",data=writeback");
  1392. else
  1393. seq_printf(s, ",data=ordered");
  1394. if (opts & OCFS2_MOUNT_BARRIER)
  1395. seq_printf(s, ",barrier=1");
  1396. if (opts & OCFS2_MOUNT_ERRORS_PANIC)
  1397. seq_printf(s, ",errors=panic");
  1398. else
  1399. seq_printf(s, ",errors=remount-ro");
  1400. if (osb->preferred_slot != OCFS2_INVALID_SLOT)
  1401. seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
  1402. if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
  1403. seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
  1404. if (osb->osb_commit_interval)
  1405. seq_printf(s, ",commit=%u",
  1406. (unsigned) (osb->osb_commit_interval / HZ));
  1407. local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
  1408. if (local_alloc_megs != ocfs2_la_default_mb(osb))
  1409. seq_printf(s, ",localalloc=%d", local_alloc_megs);
  1410. if (opts & OCFS2_MOUNT_LOCALFLOCKS)
  1411. seq_printf(s, ",localflocks,");
  1412. if (osb->osb_cluster_stack[0])
  1413. seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
  1414. osb->osb_cluster_stack);
  1415. if (opts & OCFS2_MOUNT_USRQUOTA)
  1416. seq_printf(s, ",usrquota");
  1417. if (opts & OCFS2_MOUNT_GRPQUOTA)
  1418. seq_printf(s, ",grpquota");
  1419. if (opts & OCFS2_MOUNT_COHERENCY_BUFFERED)
  1420. seq_printf(s, ",coherency=buffered");
  1421. else
  1422. seq_printf(s, ",coherency=full");
  1423. if (opts & OCFS2_MOUNT_NOUSERXATTR)
  1424. seq_printf(s, ",nouser_xattr");
  1425. else
  1426. seq_printf(s, ",user_xattr");
  1427. if (opts & OCFS2_MOUNT_INODE64)
  1428. seq_printf(s, ",inode64");
  1429. if (opts & OCFS2_MOUNT_POSIX_ACL)
  1430. seq_printf(s, ",acl");
  1431. else
  1432. seq_printf(s, ",noacl");
  1433. if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
  1434. seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
  1435. if (osb->osb_dir_resv_level != osb->osb_resv_level)
  1436. seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
  1437. return 0;
  1438. }
  1439. static int __init ocfs2_init(void)
  1440. {
  1441. int status;
  1442. mlog_entry_void();
  1443. ocfs2_print_version();
  1444. status = init_ocfs2_uptodate_cache();
  1445. if (status < 0) {
  1446. mlog_errno(status);
  1447. goto leave;
  1448. }
  1449. status = ocfs2_initialize_mem_caches();
  1450. if (status < 0) {
  1451. mlog_errno(status);
  1452. goto leave;
  1453. }
  1454. ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
  1455. if (!ocfs2_wq) {
  1456. status = -ENOMEM;
  1457. goto leave;
  1458. }
  1459. ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
  1460. if (!ocfs2_debugfs_root) {
  1461. status = -EFAULT;
  1462. mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
  1463. }
  1464. ocfs2_set_locking_protocol();
  1465. status = register_quota_format(&ocfs2_quota_format);
  1466. leave:
  1467. if (status < 0) {
  1468. ocfs2_free_mem_caches();
  1469. exit_ocfs2_uptodate_cache();
  1470. }
  1471. mlog_exit(status);
  1472. if (status >= 0) {
  1473. return register_filesystem(&ocfs2_fs_type);
  1474. } else
  1475. return -1;
  1476. }
  1477. static void __exit ocfs2_exit(void)
  1478. {
  1479. mlog_entry_void();
  1480. if (ocfs2_wq) {
  1481. flush_workqueue(ocfs2_wq);
  1482. destroy_workqueue(ocfs2_wq);
  1483. }
  1484. unregister_quota_format(&ocfs2_quota_format);
  1485. debugfs_remove(ocfs2_debugfs_root);
  1486. ocfs2_free_mem_caches();
  1487. unregister_filesystem(&ocfs2_fs_type);
  1488. exit_ocfs2_uptodate_cache();
  1489. mlog_exit_void();
  1490. }
  1491. static void ocfs2_put_super(struct super_block *sb)
  1492. {
  1493. mlog_entry("(0x%p)\n", sb);
  1494. ocfs2_sync_blockdev(sb);
  1495. ocfs2_dismount_volume(sb, 0);
  1496. mlog_exit_void();
  1497. }
  1498. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
  1499. {
  1500. struct ocfs2_super *osb;
  1501. u32 numbits, freebits;
  1502. int status;
  1503. struct ocfs2_dinode *bm_lock;
  1504. struct buffer_head *bh = NULL;
  1505. struct inode *inode = NULL;
  1506. mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
  1507. osb = OCFS2_SB(dentry->d_sb);
  1508. inode = ocfs2_get_system_file_inode(osb,
  1509. GLOBAL_BITMAP_SYSTEM_INODE,
  1510. OCFS2_INVALID_SLOT);
  1511. if (!inode) {
  1512. mlog(ML_ERROR, "failed to get bitmap inode\n");
  1513. status = -EIO;
  1514. goto bail;
  1515. }
  1516. status = ocfs2_inode_lock(inode, &bh, 0);
  1517. if (status < 0) {
  1518. mlog_errno(status);
  1519. goto bail;
  1520. }
  1521. bm_lock = (struct ocfs2_dinode *) bh->b_data;
  1522. numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
  1523. freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
  1524. buf->f_type = OCFS2_SUPER_MAGIC;
  1525. buf->f_bsize = dentry->d_sb->s_blocksize;
  1526. buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
  1527. buf->f_blocks = ((sector_t) numbits) *
  1528. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1529. buf->f_bfree = ((sector_t) freebits) *
  1530. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1531. buf->f_bavail = buf->f_bfree;
  1532. buf->f_files = numbits;
  1533. buf->f_ffree = freebits;
  1534. buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
  1535. & 0xFFFFFFFFUL;
  1536. buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
  1537. OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
  1538. brelse(bh);
  1539. ocfs2_inode_unlock(inode, 0);
  1540. status = 0;
  1541. bail:
  1542. if (inode)
  1543. iput(inode);
  1544. mlog_exit(status);
  1545. return status;
  1546. }
  1547. static void ocfs2_inode_init_once(void *data)
  1548. {
  1549. struct ocfs2_inode_info *oi = data;
  1550. oi->ip_flags = 0;
  1551. oi->ip_open_count = 0;
  1552. spin_lock_init(&oi->ip_lock);
  1553. ocfs2_extent_map_init(&oi->vfs_inode);
  1554. INIT_LIST_HEAD(&oi->ip_io_markers);
  1555. oi->ip_dir_start_lookup = 0;
  1556. init_rwsem(&oi->ip_alloc_sem);
  1557. init_rwsem(&oi->ip_xattr_sem);
  1558. mutex_init(&oi->ip_io_mutex);
  1559. oi->ip_blkno = 0ULL;
  1560. oi->ip_clusters = 0;
  1561. ocfs2_resv_init_once(&oi->ip_la_data_resv);
  1562. ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
  1563. ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
  1564. ocfs2_lock_res_init_once(&oi->ip_open_lockres);
  1565. ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
  1566. &ocfs2_inode_caching_ops);
  1567. inode_init_once(&oi->vfs_inode);
  1568. }
  1569. static int ocfs2_initialize_mem_caches(void)
  1570. {
  1571. ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
  1572. sizeof(struct ocfs2_inode_info),
  1573. 0,
  1574. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1575. SLAB_MEM_SPREAD),
  1576. ocfs2_inode_init_once);
  1577. ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
  1578. sizeof(struct ocfs2_dquot),
  1579. 0,
  1580. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1581. SLAB_MEM_SPREAD),
  1582. NULL);
  1583. ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
  1584. sizeof(struct ocfs2_quota_chunk),
  1585. 0,
  1586. (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
  1587. NULL);
  1588. if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
  1589. !ocfs2_qf_chunk_cachep) {
  1590. if (ocfs2_inode_cachep)
  1591. kmem_cache_destroy(ocfs2_inode_cachep);
  1592. if (ocfs2_dquot_cachep)
  1593. kmem_cache_destroy(ocfs2_dquot_cachep);
  1594. if (ocfs2_qf_chunk_cachep)
  1595. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1596. return -ENOMEM;
  1597. }
  1598. return 0;
  1599. }
  1600. static void ocfs2_free_mem_caches(void)
  1601. {
  1602. if (ocfs2_inode_cachep)
  1603. kmem_cache_destroy(ocfs2_inode_cachep);
  1604. ocfs2_inode_cachep = NULL;
  1605. if (ocfs2_dquot_cachep)
  1606. kmem_cache_destroy(ocfs2_dquot_cachep);
  1607. ocfs2_dquot_cachep = NULL;
  1608. if (ocfs2_qf_chunk_cachep)
  1609. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1610. ocfs2_qf_chunk_cachep = NULL;
  1611. }
  1612. static int ocfs2_get_sector(struct super_block *sb,
  1613. struct buffer_head **bh,
  1614. int block,
  1615. int sect_size)
  1616. {
  1617. if (!sb_set_blocksize(sb, sect_size)) {
  1618. mlog(ML_ERROR, "unable to set blocksize\n");
  1619. return -EIO;
  1620. }
  1621. *bh = sb_getblk(sb, block);
  1622. if (!*bh) {
  1623. mlog_errno(-EIO);
  1624. return -EIO;
  1625. }
  1626. lock_buffer(*bh);
  1627. if (!buffer_dirty(*bh))
  1628. clear_buffer_uptodate(*bh);
  1629. unlock_buffer(*bh);
  1630. ll_rw_block(READ, 1, bh);
  1631. wait_on_buffer(*bh);
  1632. if (!buffer_uptodate(*bh)) {
  1633. mlog_errno(-EIO);
  1634. brelse(*bh);
  1635. *bh = NULL;
  1636. return -EIO;
  1637. }
  1638. return 0;
  1639. }
  1640. static int ocfs2_mount_volume(struct super_block *sb)
  1641. {
  1642. int status = 0;
  1643. int unlock_super = 0;
  1644. struct ocfs2_super *osb = OCFS2_SB(sb);
  1645. mlog_entry_void();
  1646. if (ocfs2_is_hard_readonly(osb))
  1647. goto leave;
  1648. status = ocfs2_dlm_init(osb);
  1649. if (status < 0) {
  1650. mlog_errno(status);
  1651. goto leave;
  1652. }
  1653. status = ocfs2_super_lock(osb, 1);
  1654. if (status < 0) {
  1655. mlog_errno(status);
  1656. goto leave;
  1657. }
  1658. unlock_super = 1;
  1659. /* This will load up the node map and add ourselves to it. */
  1660. status = ocfs2_find_slot(osb);
  1661. if (status < 0) {
  1662. mlog_errno(status);
  1663. goto leave;
  1664. }
  1665. /* load all node-local system inodes */
  1666. status = ocfs2_init_local_system_inodes(osb);
  1667. if (status < 0) {
  1668. mlog_errno(status);
  1669. goto leave;
  1670. }
  1671. status = ocfs2_check_volume(osb);
  1672. if (status < 0) {
  1673. mlog_errno(status);
  1674. goto leave;
  1675. }
  1676. status = ocfs2_truncate_log_init(osb);
  1677. if (status < 0)
  1678. mlog_errno(status);
  1679. leave:
  1680. if (unlock_super)
  1681. ocfs2_super_unlock(osb, 1);
  1682. mlog_exit(status);
  1683. return status;
  1684. }
  1685. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
  1686. {
  1687. int tmp, hangup_needed = 0;
  1688. struct ocfs2_super *osb = NULL;
  1689. char nodestr[8];
  1690. mlog_entry("(0x%p)\n", sb);
  1691. BUG_ON(!sb);
  1692. osb = OCFS2_SB(sb);
  1693. BUG_ON(!osb);
  1694. debugfs_remove(osb->osb_ctxt);
  1695. /*
  1696. * Flush inode dropping work queue so that deletes are
  1697. * performed while the filesystem is still working
  1698. */
  1699. ocfs2_drop_all_dl_inodes(osb);
  1700. /* Orphan scan should be stopped as early as possible */
  1701. ocfs2_orphan_scan_stop(osb);
  1702. ocfs2_disable_quotas(osb);
  1703. ocfs2_shutdown_local_alloc(osb);
  1704. ocfs2_truncate_log_shutdown(osb);
  1705. /* This will disable recovery and flush any recovery work. */
  1706. ocfs2_recovery_exit(osb);
  1707. ocfs2_journal_shutdown(osb);
  1708. ocfs2_sync_blockdev(sb);
  1709. ocfs2_purge_refcount_trees(osb);
  1710. /* No cluster connection means we've failed during mount, so skip
  1711. * all the steps which depended on that to complete. */
  1712. if (osb->cconn) {
  1713. tmp = ocfs2_super_lock(osb, 1);
  1714. if (tmp < 0) {
  1715. mlog_errno(tmp);
  1716. return;
  1717. }
  1718. }
  1719. if (osb->slot_num != OCFS2_INVALID_SLOT)
  1720. ocfs2_put_slot(osb);
  1721. if (osb->cconn)
  1722. ocfs2_super_unlock(osb, 1);
  1723. ocfs2_release_system_inodes(osb);
  1724. /*
  1725. * If we're dismounting due to mount error, mount.ocfs2 will clean
  1726. * up heartbeat. If we're a local mount, there is no heartbeat.
  1727. * If we failed before we got a uuid_str yet, we can't stop
  1728. * heartbeat. Otherwise, do it.
  1729. */
  1730. if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
  1731. hangup_needed = 1;
  1732. if (osb->cconn)
  1733. ocfs2_dlm_shutdown(osb, hangup_needed);
  1734. ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
  1735. debugfs_remove(osb->osb_debug_root);
  1736. if (hangup_needed)
  1737. ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
  1738. atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
  1739. if (ocfs2_mount_local(osb))
  1740. snprintf(nodestr, sizeof(nodestr), "local");
  1741. else
  1742. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1743. printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
  1744. osb->dev_str, nodestr);
  1745. ocfs2_delete_osb(osb);
  1746. kfree(osb);
  1747. sb->s_dev = 0;
  1748. sb->s_fs_info = NULL;
  1749. }
  1750. static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
  1751. unsigned uuid_bytes)
  1752. {
  1753. int i, ret;
  1754. char *ptr;
  1755. BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
  1756. osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
  1757. if (osb->uuid_str == NULL)
  1758. return -ENOMEM;
  1759. for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
  1760. /* print with null */
  1761. ret = snprintf(ptr, 3, "%02X", uuid[i]);
  1762. if (ret != 2) /* drop super cleans up */
  1763. return -EINVAL;
  1764. /* then only advance past the last char */
  1765. ptr += 2;
  1766. }
  1767. return 0;
  1768. }
  1769. /* Make sure entire volume is addressable by our journal. Requires
  1770. osb_clusters_at_boot to be valid and for the journal to have been
  1771. initialized by ocfs2_journal_init(). */
  1772. static int ocfs2_journal_addressable(struct ocfs2_super *osb)
  1773. {
  1774. int status = 0;
  1775. u64 max_block =
  1776. ocfs2_clusters_to_blocks(osb->sb,
  1777. osb->osb_clusters_at_boot) - 1;
  1778. /* 32-bit block number is always OK. */
  1779. if (max_block <= (u32)~0ULL)
  1780. goto out;
  1781. /* Volume is "huge", so see if our journal is new enough to
  1782. support it. */
  1783. if (!(OCFS2_HAS_COMPAT_FEATURE(osb->sb,
  1784. OCFS2_FEATURE_COMPAT_JBD2_SB) &&
  1785. jbd2_journal_check_used_features(osb->journal->j_journal, 0, 0,
  1786. JBD2_FEATURE_INCOMPAT_64BIT))) {
  1787. mlog(ML_ERROR, "The journal cannot address the entire volume. "
  1788. "Enable the 'block64' journal option with tunefs.ocfs2");
  1789. status = -EFBIG;
  1790. goto out;
  1791. }
  1792. out:
  1793. return status;
  1794. }
  1795. static int ocfs2_initialize_super(struct super_block *sb,
  1796. struct buffer_head *bh,
  1797. int sector_size,
  1798. struct ocfs2_blockcheck_stats *stats)
  1799. {
  1800. int status;
  1801. int i, cbits, bbits;
  1802. struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
  1803. struct inode *inode = NULL;
  1804. struct ocfs2_journal *journal;
  1805. __le32 uuid_net_key;
  1806. struct ocfs2_super *osb;
  1807. u64 total_blocks;
  1808. mlog_entry_void();
  1809. osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
  1810. if (!osb) {
  1811. status = -ENOMEM;
  1812. mlog_errno(status);
  1813. goto bail;
  1814. }
  1815. sb->s_fs_info = osb;
  1816. sb->s_op = &ocfs2_sops;
  1817. sb->s_d_op = &ocfs2_dentry_ops;
  1818. sb->s_export_op = &ocfs2_export_ops;
  1819. sb->s_qcop = &ocfs2_quotactl_ops;
  1820. sb->dq_op = &ocfs2_quota_operations;
  1821. sb->s_xattr = ocfs2_xattr_handlers;
  1822. sb->s_time_gran = 1;
  1823. sb->s_flags |= MS_NOATIME;
  1824. /* this is needed to support O_LARGEFILE */
  1825. cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1826. bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
  1827. sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
  1828. osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
  1829. for (i = 0; i < 3; i++)
  1830. osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
  1831. osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1832. osb->sb = sb;
  1833. /* Save off for ocfs2_rw_direct */
  1834. osb->s_sectsize_bits = blksize_bits(sector_size);
  1835. BUG_ON(!osb->s_sectsize_bits);
  1836. spin_lock_init(&osb->dc_task_lock);
  1837. init_waitqueue_head(&osb->dc_event);
  1838. osb->dc_work_sequence = 0;
  1839. osb->dc_wake_sequence = 0;
  1840. INIT_LIST_HEAD(&osb->blocked_lock_list);
  1841. osb->blocked_lock_count = 0;
  1842. spin_lock_init(&osb->osb_lock);
  1843. spin_lock_init(&osb->osb_xattr_lock);
  1844. ocfs2_init_steal_slots(osb);
  1845. atomic_set(&osb->alloc_stats.moves, 0);
  1846. atomic_set(&osb->alloc_stats.local_data, 0);
  1847. atomic_set(&osb->alloc_stats.bitmap_data, 0);
  1848. atomic_set(&osb->alloc_stats.bg_allocs, 0);
  1849. atomic_set(&osb->alloc_stats.bg_extends, 0);
  1850. /* Copy the blockcheck stats from the superblock probe */
  1851. osb->osb_ecc_stats = *stats;
  1852. ocfs2_init_node_maps(osb);
  1853. snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
  1854. MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
  1855. osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
  1856. if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
  1857. mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
  1858. osb->max_slots);
  1859. status = -EINVAL;
  1860. goto bail;
  1861. }
  1862. mlog(0, "max_slots for this device: %u\n", osb->max_slots);
  1863. ocfs2_orphan_scan_init(osb);
  1864. status = ocfs2_recovery_init(osb);
  1865. if (status) {
  1866. mlog(ML_ERROR, "Unable to initialize recovery state\n");
  1867. mlog_errno(status);
  1868. goto bail;
  1869. }
  1870. init_waitqueue_head(&osb->checkpoint_event);
  1871. atomic_set(&osb->needs_checkpoint, 0);
  1872. osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1873. osb->slot_num = OCFS2_INVALID_SLOT;
  1874. osb->s_xattr_inline_size = le16_to_cpu(
  1875. di->id2.i_super.s_xattr_inline_size);
  1876. osb->local_alloc_state = OCFS2_LA_UNUSED;
  1877. osb->local_alloc_bh = NULL;
  1878. INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
  1879. init_waitqueue_head(&osb->osb_mount_event);
  1880. status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
  1881. if (status) {
  1882. mlog_errno(status);
  1883. goto bail;
  1884. }
  1885. osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
  1886. if (!osb->vol_label) {
  1887. mlog(ML_ERROR, "unable to alloc vol label\n");
  1888. status = -ENOMEM;
  1889. goto bail;
  1890. }
  1891. osb->slot_recovery_generations =
  1892. kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
  1893. GFP_KERNEL);
  1894. if (!osb->slot_recovery_generations) {
  1895. status = -ENOMEM;
  1896. mlog_errno(status);
  1897. goto bail;
  1898. }
  1899. init_waitqueue_head(&osb->osb_wipe_event);
  1900. osb->osb_orphan_wipes = kcalloc(osb->max_slots,
  1901. sizeof(*osb->osb_orphan_wipes),
  1902. GFP_KERNEL);
  1903. if (!osb->osb_orphan_wipes) {
  1904. status = -ENOMEM;
  1905. mlog_errno(status);
  1906. goto bail;
  1907. }
  1908. osb->osb_rf_lock_tree = RB_ROOT;
  1909. osb->s_feature_compat =
  1910. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
  1911. osb->s_feature_ro_compat =
  1912. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
  1913. osb->s_feature_incompat =
  1914. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
  1915. if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
  1916. mlog(ML_ERROR, "couldn't mount because of unsupported "
  1917. "optional features (%x).\n", i);
  1918. status = -EINVAL;
  1919. goto bail;
  1920. }
  1921. if (!(osb->sb->s_flags & MS_RDONLY) &&
  1922. (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
  1923. mlog(ML_ERROR, "couldn't mount RDWR because of "
  1924. "unsupported optional features (%x).\n", i);
  1925. status = -EINVAL;
  1926. goto bail;
  1927. }
  1928. if (ocfs2_clusterinfo_valid(osb)) {
  1929. osb->osb_stackflags =
  1930. OCFS2_RAW_SB(di)->s_cluster_info.ci_stackflags;
  1931. memcpy(osb->osb_cluster_stack,
  1932. OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
  1933. OCFS2_STACK_LABEL_LEN);
  1934. osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1935. if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
  1936. mlog(ML_ERROR,
  1937. "couldn't mount because of an invalid "
  1938. "cluster stack label (%s) \n",
  1939. osb->osb_cluster_stack);
  1940. status = -EINVAL;
  1941. goto bail;
  1942. }
  1943. } else {
  1944. /* The empty string is identical with classic tools that
  1945. * don't know about s_cluster_info. */
  1946. osb->osb_cluster_stack[0] = '\0';
  1947. }
  1948. get_random_bytes(&osb->s_next_generation, sizeof(u32));
  1949. /* FIXME
  1950. * This should be done in ocfs2_journal_init(), but unknown
  1951. * ordering issues will cause the filesystem to crash.
  1952. * If anyone wants to figure out what part of the code
  1953. * refers to osb->journal before ocfs2_journal_init() is run,
  1954. * be my guest.
  1955. */
  1956. /* initialize our journal structure */
  1957. journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
  1958. if (!journal) {
  1959. mlog(ML_ERROR, "unable to alloc journal\n");
  1960. status = -ENOMEM;
  1961. goto bail;
  1962. }
  1963. osb->journal = journal;
  1964. journal->j_osb = osb;
  1965. atomic_set(&journal->j_num_trans, 0);
  1966. init_rwsem(&journal->j_trans_barrier);
  1967. init_waitqueue_head(&journal->j_checkpointed);
  1968. spin_lock_init(&journal->j_lock);
  1969. journal->j_trans_id = (unsigned long) 1;
  1970. INIT_LIST_HEAD(&journal->j_la_cleanups);
  1971. INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
  1972. journal->j_state = OCFS2_JOURNAL_FREE;
  1973. INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
  1974. osb->dentry_lock_list = NULL;
  1975. /* get some pseudo constants for clustersize bits */
  1976. osb->s_clustersize_bits =
  1977. le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1978. osb->s_clustersize = 1 << osb->s_clustersize_bits;
  1979. mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
  1980. if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
  1981. osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
  1982. mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
  1983. osb->s_clustersize);
  1984. status = -EINVAL;
  1985. goto bail;
  1986. }
  1987. total_blocks = ocfs2_clusters_to_blocks(osb->sb,
  1988. le32_to_cpu(di->i_clusters));
  1989. status = generic_check_addressable(osb->sb->s_blocksize_bits,
  1990. total_blocks);
  1991. if (status) {
  1992. mlog(ML_ERROR, "Volume too large "
  1993. "to mount safely on this system");
  1994. status = -EFBIG;
  1995. goto bail;
  1996. }
  1997. if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
  1998. sizeof(di->id2.i_super.s_uuid))) {
  1999. mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
  2000. status = -ENOMEM;
  2001. goto bail;
  2002. }
  2003. memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
  2004. strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
  2005. osb->vol_label[63] = '\0';
  2006. osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
  2007. osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
  2008. osb->first_cluster_group_blkno =
  2009. le64_to_cpu(di->id2.i_super.s_first_cluster_group);
  2010. osb->fs_generation = le32_to_cpu(di->i_fs_generation);
  2011. osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  2012. mlog(0, "vol_label: %s\n", osb->vol_label);
  2013. mlog(0, "uuid: %s\n", osb->uuid_str);
  2014. mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
  2015. (unsigned long long)osb->root_blkno,
  2016. (unsigned long long)osb->system_dir_blkno);
  2017. osb->osb_dlm_debug = ocfs2_new_dlm_debug();
  2018. if (!osb->osb_dlm_debug) {
  2019. status = -ENOMEM;
  2020. mlog_errno(status);
  2021. goto bail;
  2022. }
  2023. atomic_set(&osb->vol_state, VOLUME_INIT);
  2024. /* load root, system_dir, and all global system inodes */
  2025. status = ocfs2_init_global_system_inodes(osb);
  2026. if (status < 0) {
  2027. mlog_errno(status);
  2028. goto bail;
  2029. }
  2030. /*
  2031. * global bitmap
  2032. */
  2033. inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
  2034. OCFS2_INVALID_SLOT);
  2035. if (!inode) {
  2036. status = -EINVAL;
  2037. mlog_errno(status);
  2038. goto bail;
  2039. }
  2040. osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
  2041. osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
  2042. iput(inode);
  2043. osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
  2044. osb->s_feature_incompat) * 8;
  2045. status = ocfs2_init_slot_info(osb);
  2046. if (status < 0) {
  2047. mlog_errno(status);
  2048. goto bail;
  2049. }
  2050. bail:
  2051. mlog_exit(status);
  2052. return status;
  2053. }
  2054. /*
  2055. * will return: -EAGAIN if it is ok to keep searching for superblocks
  2056. * -EINVAL if there is a bad superblock
  2057. * 0 on success
  2058. */
  2059. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  2060. struct buffer_head *bh,
  2061. u32 blksz,
  2062. struct ocfs2_blockcheck_stats *stats)
  2063. {
  2064. int status = -EAGAIN;
  2065. mlog_entry_void();
  2066. if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
  2067. strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
  2068. /* We have to do a raw check of the feature here */
  2069. if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
  2070. OCFS2_FEATURE_INCOMPAT_META_ECC) {
  2071. status = ocfs2_block_check_validate(bh->b_data,
  2072. bh->b_size,
  2073. &di->i_check,
  2074. stats);
  2075. if (status)
  2076. goto out;
  2077. }
  2078. status = -EINVAL;
  2079. if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
  2080. mlog(ML_ERROR, "found superblock with incorrect block "
  2081. "size: found %u, should be %u\n",
  2082. 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
  2083. blksz);
  2084. } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
  2085. OCFS2_MAJOR_REV_LEVEL ||
  2086. le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
  2087. OCFS2_MINOR_REV_LEVEL) {
  2088. mlog(ML_ERROR, "found superblock with bad version: "
  2089. "found %u.%u, should be %u.%u\n",
  2090. le16_to_cpu(di->id2.i_super.s_major_rev_level),
  2091. le16_to_cpu(di->id2.i_super.s_minor_rev_level),
  2092. OCFS2_MAJOR_REV_LEVEL,
  2093. OCFS2_MINOR_REV_LEVEL);
  2094. } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
  2095. mlog(ML_ERROR, "bad block number on superblock: "
  2096. "found %llu, should be %llu\n",
  2097. (unsigned long long)le64_to_cpu(di->i_blkno),
  2098. (unsigned long long)bh->b_blocknr);
  2099. } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
  2100. le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
  2101. mlog(ML_ERROR, "bad cluster size found: %u\n",
  2102. 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
  2103. } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
  2104. mlog(ML_ERROR, "bad root_blkno: 0\n");
  2105. } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
  2106. mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
  2107. } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
  2108. mlog(ML_ERROR,
  2109. "Superblock slots found greater than file system "
  2110. "maximum: found %u, max %u\n",
  2111. le16_to_cpu(di->id2.i_super.s_max_slots),
  2112. OCFS2_MAX_SLOTS);
  2113. } else {
  2114. /* found it! */
  2115. status = 0;
  2116. }
  2117. }
  2118. out:
  2119. mlog_exit(status);
  2120. return status;
  2121. }
  2122. static int ocfs2_check_volume(struct ocfs2_super *osb)
  2123. {
  2124. int status;
  2125. int dirty;
  2126. int local;
  2127. struct ocfs2_dinode *local_alloc = NULL; /* only used if we
  2128. * recover
  2129. * ourselves. */
  2130. mlog_entry_void();
  2131. /* Init our journal object. */
  2132. status = ocfs2_journal_init(osb->journal, &dirty);
  2133. if (status < 0) {
  2134. mlog(ML_ERROR, "Could not initialize journal!\n");
  2135. goto finally;
  2136. }
  2137. /* Now that journal has been initialized, check to make sure
  2138. entire volume is addressable. */
  2139. status = ocfs2_journal_addressable(osb);
  2140. if (status)
  2141. goto finally;
  2142. /* If the journal was unmounted cleanly then we don't want to
  2143. * recover anything. Otherwise, journal_load will do that
  2144. * dirty work for us :) */
  2145. if (!dirty) {
  2146. status = ocfs2_journal_wipe(osb->journal, 0);
  2147. if (status < 0) {
  2148. mlog_errno(status);
  2149. goto finally;
  2150. }
  2151. } else {
  2152. mlog(ML_NOTICE, "File system was not unmounted cleanly, "
  2153. "recovering volume.\n");
  2154. }
  2155. local = ocfs2_mount_local(osb);
  2156. /* will play back anything left in the journal. */
  2157. status = ocfs2_journal_load(osb->journal, local, dirty);
  2158. if (status < 0) {
  2159. mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
  2160. goto finally;
  2161. }
  2162. if (dirty) {
  2163. /* recover my local alloc if we didn't unmount cleanly. */
  2164. status = ocfs2_begin_local_alloc_recovery(osb,
  2165. osb->slot_num,
  2166. &local_alloc);
  2167. if (status < 0) {
  2168. mlog_errno(status);
  2169. goto finally;
  2170. }
  2171. /* we complete the recovery process after we've marked
  2172. * ourselves as mounted. */
  2173. }
  2174. mlog(0, "Journal loaded.\n");
  2175. status = ocfs2_load_local_alloc(osb);
  2176. if (status < 0) {
  2177. mlog_errno(status);
  2178. goto finally;
  2179. }
  2180. if (dirty) {
  2181. /* Recovery will be completed after we've mounted the
  2182. * rest of the volume. */
  2183. osb->dirty = 1;
  2184. osb->local_alloc_copy = local_alloc;
  2185. local_alloc = NULL;
  2186. }
  2187. /* go through each journal, trylock it and if you get the
  2188. * lock, and it's marked as dirty, set the bit in the recover
  2189. * map and launch a recovery thread for it. */
  2190. status = ocfs2_mark_dead_nodes(osb);
  2191. if (status < 0) {
  2192. mlog_errno(status);
  2193. goto finally;
  2194. }
  2195. status = ocfs2_compute_replay_slots(osb);
  2196. if (status < 0)
  2197. mlog_errno(status);
  2198. finally:
  2199. if (local_alloc)
  2200. kfree(local_alloc);
  2201. mlog_exit(status);
  2202. return status;
  2203. }
  2204. /*
  2205. * The routine gets called from dismount or close whenever a dismount on
  2206. * volume is requested and the osb open count becomes 1.
  2207. * It will remove the osb from the global list and also free up all the
  2208. * initialized resources and fileobject.
  2209. */
  2210. static void ocfs2_delete_osb(struct ocfs2_super *osb)
  2211. {
  2212. mlog_entry_void();
  2213. /* This function assumes that the caller has the main osb resource */
  2214. ocfs2_free_slot_info(osb);
  2215. kfree(osb->osb_orphan_wipes);
  2216. kfree(osb->slot_recovery_generations);
  2217. /* FIXME
  2218. * This belongs in journal shutdown, but because we have to
  2219. * allocate osb->journal at the start of ocfs2_initialize_osb(),
  2220. * we free it here.
  2221. */
  2222. kfree(osb->journal);
  2223. if (osb->local_alloc_copy)
  2224. kfree(osb->local_alloc_copy);
  2225. kfree(osb->uuid_str);
  2226. ocfs2_put_dlm_debug(osb->osb_dlm_debug);
  2227. memset(osb, 0, sizeof(struct ocfs2_super));
  2228. mlog_exit_void();
  2229. }
  2230. /* Put OCFS2 into a readonly state, or (if the user specifies it),
  2231. * panic(). We do not support continue-on-error operation. */
  2232. static void ocfs2_handle_error(struct super_block *sb)
  2233. {
  2234. struct ocfs2_super *osb = OCFS2_SB(sb);
  2235. if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
  2236. panic("OCFS2: (device %s): panic forced after error\n",
  2237. sb->s_id);
  2238. ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
  2239. if (sb->s_flags & MS_RDONLY &&
  2240. (ocfs2_is_soft_readonly(osb) ||
  2241. ocfs2_is_hard_readonly(osb)))
  2242. return;
  2243. printk(KERN_CRIT "File system is now read-only due to the potential "
  2244. "of on-disk corruption. Please run fsck.ocfs2 once the file "
  2245. "system is unmounted.\n");
  2246. sb->s_flags |= MS_RDONLY;
  2247. ocfs2_set_ro_flag(osb, 0);
  2248. }
  2249. static char error_buf[1024];
  2250. void __ocfs2_error(struct super_block *sb,
  2251. const char *function,
  2252. const char *fmt, ...)
  2253. {
  2254. va_list args;
  2255. va_start(args, fmt);
  2256. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  2257. va_end(args);
  2258. /* Not using mlog here because we want to show the actual
  2259. * function the error came from. */
  2260. printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
  2261. sb->s_id, function, error_buf);
  2262. ocfs2_handle_error(sb);
  2263. }
  2264. /* Handle critical errors. This is intentionally more drastic than
  2265. * ocfs2_handle_error, so we only use for things like journal errors,
  2266. * etc. */
  2267. void __ocfs2_abort(struct super_block* sb,
  2268. const char *function,
  2269. const char *fmt, ...)
  2270. {
  2271. va_list args;
  2272. va_start(args, fmt);
  2273. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  2274. va_end(args);
  2275. printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
  2276. sb->s_id, function, error_buf);
  2277. /* We don't have the cluster support yet to go straight to
  2278. * hard readonly in here. Until then, we want to keep
  2279. * ocfs2_abort() so that we can at least mark critical
  2280. * errors.
  2281. *
  2282. * TODO: This should abort the journal and alert other nodes
  2283. * that our slot needs recovery. */
  2284. /* Force a panic(). This stinks, but it's better than letting
  2285. * things continue without having a proper hard readonly
  2286. * here. */
  2287. if (!ocfs2_mount_local(OCFS2_SB(sb)))
  2288. OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  2289. ocfs2_handle_error(sb);
  2290. }
  2291. /*
  2292. * Void signal blockers, because in-kernel sigprocmask() only fails
  2293. * when SIG_* is wrong.
  2294. */
  2295. void ocfs2_block_signals(sigset_t *oldset)
  2296. {
  2297. int rc;
  2298. sigset_t blocked;
  2299. sigfillset(&blocked);
  2300. rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
  2301. BUG_ON(rc);
  2302. }
  2303. void ocfs2_unblock_signals(sigset_t *oldset)
  2304. {
  2305. int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
  2306. BUG_ON(rc);
  2307. }
  2308. module_init(ocfs2_init);
  2309. module_exit(ocfs2_exit);