super.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949
  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/utsname.h>
  31. #include <linux/init.h>
  32. #include <linux/random.h>
  33. #include <linux/statfs.h>
  34. #include <linux/moduleparam.h>
  35. #include <linux/blkdev.h>
  36. #include <linux/socket.h>
  37. #include <linux/inet.h>
  38. #include <linux/parser.h>
  39. #include <linux/crc32.h>
  40. #include <linux/debugfs.h>
  41. #include <linux/mount.h>
  42. #include <linux/seq_file.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 "dlmglue.h"
  50. #include "export.h"
  51. #include "extent_map.h"
  52. #include "heartbeat.h"
  53. #include "inode.h"
  54. #include "journal.h"
  55. #include "localalloc.h"
  56. #include "namei.h"
  57. #include "slot_map.h"
  58. #include "super.h"
  59. #include "sysfile.h"
  60. #include "uptodate.h"
  61. #include "ver.h"
  62. #include "xattr.h"
  63. #include "buffer_head_io.h"
  64. static struct kmem_cache *ocfs2_inode_cachep = NULL;
  65. /* OCFS2 needs to schedule several differnt types of work which
  66. * require cluster locking, disk I/O, recovery waits, etc. Since these
  67. * types of work tend to be heavy we avoid using the kernel events
  68. * workqueue and schedule on our own. */
  69. struct workqueue_struct *ocfs2_wq = NULL;
  70. static struct dentry *ocfs2_debugfs_root = NULL;
  71. MODULE_AUTHOR("Oracle");
  72. MODULE_LICENSE("GPL");
  73. struct mount_options
  74. {
  75. unsigned long commit_interval;
  76. unsigned long mount_opt;
  77. unsigned int atime_quantum;
  78. signed short slot;
  79. unsigned int localalloc_opt;
  80. char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
  81. };
  82. static int ocfs2_parse_options(struct super_block *sb, char *options,
  83. struct mount_options *mopt,
  84. int is_remount);
  85. static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
  86. static void ocfs2_put_super(struct super_block *sb);
  87. static int ocfs2_mount_volume(struct super_block *sb);
  88. static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
  89. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
  90. static int ocfs2_initialize_mem_caches(void);
  91. static void ocfs2_free_mem_caches(void);
  92. static void ocfs2_delete_osb(struct ocfs2_super *osb);
  93. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
  94. static int ocfs2_sync_fs(struct super_block *sb, int wait);
  95. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
  96. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
  97. static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
  98. static int ocfs2_check_volume(struct ocfs2_super *osb);
  99. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  100. struct buffer_head *bh,
  101. u32 sectsize);
  102. static int ocfs2_initialize_super(struct super_block *sb,
  103. struct buffer_head *bh,
  104. int sector_size);
  105. static int ocfs2_get_sector(struct super_block *sb,
  106. struct buffer_head **bh,
  107. int block,
  108. int sect_size);
  109. static void ocfs2_write_super(struct super_block *sb);
  110. static struct inode *ocfs2_alloc_inode(struct super_block *sb);
  111. static void ocfs2_destroy_inode(struct inode *inode);
  112. static const struct super_operations ocfs2_sops = {
  113. .statfs = ocfs2_statfs,
  114. .alloc_inode = ocfs2_alloc_inode,
  115. .destroy_inode = ocfs2_destroy_inode,
  116. .drop_inode = ocfs2_drop_inode,
  117. .clear_inode = ocfs2_clear_inode,
  118. .delete_inode = ocfs2_delete_inode,
  119. .sync_fs = ocfs2_sync_fs,
  120. .write_super = ocfs2_write_super,
  121. .put_super = ocfs2_put_super,
  122. .remount_fs = ocfs2_remount,
  123. .show_options = ocfs2_show_options,
  124. };
  125. enum {
  126. Opt_barrier,
  127. Opt_err_panic,
  128. Opt_err_ro,
  129. Opt_intr,
  130. Opt_nointr,
  131. Opt_hb_none,
  132. Opt_hb_local,
  133. Opt_data_ordered,
  134. Opt_data_writeback,
  135. Opt_atime_quantum,
  136. Opt_slot,
  137. Opt_commit,
  138. Opt_localalloc,
  139. Opt_localflocks,
  140. Opt_stack,
  141. Opt_user_xattr,
  142. Opt_nouser_xattr,
  143. Opt_inode64,
  144. Opt_acl,
  145. Opt_noacl,
  146. Opt_err,
  147. };
  148. static const match_table_t tokens = {
  149. {Opt_barrier, "barrier=%u"},
  150. {Opt_err_panic, "errors=panic"},
  151. {Opt_err_ro, "errors=remount-ro"},
  152. {Opt_intr, "intr"},
  153. {Opt_nointr, "nointr"},
  154. {Opt_hb_none, OCFS2_HB_NONE},
  155. {Opt_hb_local, OCFS2_HB_LOCAL},
  156. {Opt_data_ordered, "data=ordered"},
  157. {Opt_data_writeback, "data=writeback"},
  158. {Opt_atime_quantum, "atime_quantum=%u"},
  159. {Opt_slot, "preferred_slot=%u"},
  160. {Opt_commit, "commit=%u"},
  161. {Opt_localalloc, "localalloc=%d"},
  162. {Opt_localflocks, "localflocks"},
  163. {Opt_stack, "cluster_stack=%s"},
  164. {Opt_user_xattr, "user_xattr"},
  165. {Opt_nouser_xattr, "nouser_xattr"},
  166. {Opt_inode64, "inode64"},
  167. {Opt_acl, "acl"},
  168. {Opt_noacl, "noacl"},
  169. {Opt_err, NULL}
  170. };
  171. /*
  172. * write_super and sync_fs ripped right out of ext3.
  173. */
  174. static void ocfs2_write_super(struct super_block *sb)
  175. {
  176. if (mutex_trylock(&sb->s_lock) != 0)
  177. BUG();
  178. sb->s_dirt = 0;
  179. }
  180. static int ocfs2_sync_fs(struct super_block *sb, int wait)
  181. {
  182. int status;
  183. tid_t target;
  184. struct ocfs2_super *osb = OCFS2_SB(sb);
  185. sb->s_dirt = 0;
  186. if (ocfs2_is_hard_readonly(osb))
  187. return -EROFS;
  188. if (wait) {
  189. status = ocfs2_flush_truncate_log(osb);
  190. if (status < 0)
  191. mlog_errno(status);
  192. } else {
  193. ocfs2_schedule_truncate_log_flush(osb, 0);
  194. }
  195. if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
  196. &target)) {
  197. if (wait)
  198. jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
  199. target);
  200. }
  201. return 0;
  202. }
  203. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
  204. {
  205. struct inode *new = NULL;
  206. int status = 0;
  207. int i;
  208. mlog_entry_void();
  209. new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  210. if (IS_ERR(new)) {
  211. status = PTR_ERR(new);
  212. mlog_errno(status);
  213. goto bail;
  214. }
  215. osb->root_inode = new;
  216. new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  217. if (IS_ERR(new)) {
  218. status = PTR_ERR(new);
  219. mlog_errno(status);
  220. goto bail;
  221. }
  222. osb->sys_root_inode = new;
  223. for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
  224. i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
  225. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  226. if (!new) {
  227. ocfs2_release_system_inodes(osb);
  228. status = -EINVAL;
  229. mlog_errno(status);
  230. /* FIXME: Should ERROR_RO_FS */
  231. mlog(ML_ERROR, "Unable to load system inode %d, "
  232. "possibly corrupt fs?", i);
  233. goto bail;
  234. }
  235. // the array now has one ref, so drop this one
  236. iput(new);
  237. }
  238. bail:
  239. mlog_exit(status);
  240. return status;
  241. }
  242. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
  243. {
  244. struct inode *new = NULL;
  245. int status = 0;
  246. int i;
  247. mlog_entry_void();
  248. for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
  249. i < NUM_SYSTEM_INODES;
  250. i++) {
  251. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  252. if (!new) {
  253. ocfs2_release_system_inodes(osb);
  254. status = -EINVAL;
  255. mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
  256. status, i, osb->slot_num);
  257. goto bail;
  258. }
  259. /* the array now has one ref, so drop this one */
  260. iput(new);
  261. }
  262. bail:
  263. mlog_exit(status);
  264. return status;
  265. }
  266. static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
  267. {
  268. int i;
  269. struct inode *inode;
  270. mlog_entry_void();
  271. for (i = 0; i < NUM_SYSTEM_INODES; i++) {
  272. inode = osb->system_inodes[i];
  273. if (inode) {
  274. iput(inode);
  275. osb->system_inodes[i] = NULL;
  276. }
  277. }
  278. inode = osb->sys_root_inode;
  279. if (inode) {
  280. iput(inode);
  281. osb->sys_root_inode = NULL;
  282. }
  283. inode = osb->root_inode;
  284. if (inode) {
  285. iput(inode);
  286. osb->root_inode = NULL;
  287. }
  288. mlog_exit(0);
  289. }
  290. /* We're allocating fs objects, use GFP_NOFS */
  291. static struct inode *ocfs2_alloc_inode(struct super_block *sb)
  292. {
  293. struct ocfs2_inode_info *oi;
  294. oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
  295. if (!oi)
  296. return NULL;
  297. jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
  298. return &oi->vfs_inode;
  299. }
  300. static void ocfs2_destroy_inode(struct inode *inode)
  301. {
  302. kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
  303. }
  304. static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
  305. unsigned int cbits)
  306. {
  307. unsigned int bytes = 1 << cbits;
  308. unsigned int trim = bytes;
  309. unsigned int bitshift = 32;
  310. /*
  311. * i_size and all block offsets in ocfs2 are always 64 bits
  312. * wide. i_clusters is 32 bits, in cluster-sized units. So on
  313. * 64 bit platforms, cluster size will be the limiting factor.
  314. */
  315. #if BITS_PER_LONG == 32
  316. # if defined(CONFIG_LBD)
  317. BUILD_BUG_ON(sizeof(sector_t) != 8);
  318. /*
  319. * We might be limited by page cache size.
  320. */
  321. if (bytes > PAGE_CACHE_SIZE) {
  322. bytes = PAGE_CACHE_SIZE;
  323. trim = 1;
  324. /*
  325. * Shift by 31 here so that we don't get larger than
  326. * MAX_LFS_FILESIZE
  327. */
  328. bitshift = 31;
  329. }
  330. # else
  331. /*
  332. * We are limited by the size of sector_t. Use block size, as
  333. * that's what we expose to the VFS.
  334. */
  335. bytes = 1 << bbits;
  336. trim = 1;
  337. bitshift = 31;
  338. # endif
  339. #endif
  340. /*
  341. * Trim by a whole cluster when we can actually approach the
  342. * on-disk limits. Otherwise we can overflow i_clusters when
  343. * an extent start is at the max offset.
  344. */
  345. return (((unsigned long long)bytes) << bitshift) - trim;
  346. }
  347. static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
  348. {
  349. int incompat_features;
  350. int ret = 0;
  351. struct mount_options parsed_options;
  352. struct ocfs2_super *osb = OCFS2_SB(sb);
  353. if (!ocfs2_parse_options(sb, data, &parsed_options, 1)) {
  354. ret = -EINVAL;
  355. goto out;
  356. }
  357. if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
  358. (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
  359. ret = -EINVAL;
  360. mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
  361. goto out;
  362. }
  363. if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
  364. (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
  365. ret = -EINVAL;
  366. mlog(ML_ERROR, "Cannot change data mode on remount\n");
  367. goto out;
  368. }
  369. /* Probably don't want this on remount; it might
  370. * mess with other nodes */
  371. if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
  372. (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
  373. ret = -EINVAL;
  374. mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
  375. goto out;
  376. }
  377. /* We're going to/from readonly mode. */
  378. if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
  379. /* Lock here so the check of HARD_RO and the potential
  380. * setting of SOFT_RO is atomic. */
  381. spin_lock(&osb->osb_lock);
  382. if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
  383. mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
  384. ret = -EROFS;
  385. goto unlock_osb;
  386. }
  387. if (*flags & MS_RDONLY) {
  388. mlog(0, "Going to ro mode.\n");
  389. sb->s_flags |= MS_RDONLY;
  390. osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  391. } else {
  392. mlog(0, "Making ro filesystem writeable.\n");
  393. if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
  394. mlog(ML_ERROR, "Cannot remount RDWR "
  395. "filesystem due to previous errors.\n");
  396. ret = -EROFS;
  397. goto unlock_osb;
  398. }
  399. incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
  400. if (incompat_features) {
  401. mlog(ML_ERROR, "Cannot remount RDWR because "
  402. "of unsupported optional features "
  403. "(%x).\n", incompat_features);
  404. ret = -EINVAL;
  405. goto unlock_osb;
  406. }
  407. sb->s_flags &= ~MS_RDONLY;
  408. osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
  409. }
  410. unlock_osb:
  411. spin_unlock(&osb->osb_lock);
  412. }
  413. if (!ret) {
  414. /* Only save off the new mount options in case of a successful
  415. * remount. */
  416. if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
  417. parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  418. osb->s_mount_opt = parsed_options.mount_opt;
  419. osb->s_atime_quantum = parsed_options.atime_quantum;
  420. osb->preferred_slot = parsed_options.slot;
  421. if (parsed_options.commit_interval)
  422. osb->osb_commit_interval = parsed_options.commit_interval;
  423. if (!ocfs2_is_hard_readonly(osb))
  424. ocfs2_set_journal_params(osb);
  425. }
  426. out:
  427. return ret;
  428. }
  429. static int ocfs2_sb_probe(struct super_block *sb,
  430. struct buffer_head **bh,
  431. int *sector_size)
  432. {
  433. int status, tmpstat;
  434. struct ocfs1_vol_disk_hdr *hdr;
  435. struct ocfs2_dinode *di;
  436. int blksize;
  437. *bh = NULL;
  438. /* may be > 512 */
  439. *sector_size = bdev_hardsect_size(sb->s_bdev);
  440. if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
  441. mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
  442. *sector_size, OCFS2_MAX_BLOCKSIZE);
  443. status = -EINVAL;
  444. goto bail;
  445. }
  446. /* Can this really happen? */
  447. if (*sector_size < OCFS2_MIN_BLOCKSIZE)
  448. *sector_size = OCFS2_MIN_BLOCKSIZE;
  449. /* check block zero for old format */
  450. status = ocfs2_get_sector(sb, bh, 0, *sector_size);
  451. if (status < 0) {
  452. mlog_errno(status);
  453. goto bail;
  454. }
  455. hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
  456. if (hdr->major_version == OCFS1_MAJOR_VERSION) {
  457. mlog(ML_ERROR, "incompatible version: %u.%u\n",
  458. hdr->major_version, hdr->minor_version);
  459. status = -EINVAL;
  460. }
  461. if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
  462. strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
  463. mlog(ML_ERROR, "incompatible volume signature: %8s\n",
  464. hdr->signature);
  465. status = -EINVAL;
  466. }
  467. brelse(*bh);
  468. *bh = NULL;
  469. if (status < 0) {
  470. mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
  471. "upgraded before mounting with ocfs v2\n");
  472. goto bail;
  473. }
  474. /*
  475. * Now check at magic offset for 512, 1024, 2048, 4096
  476. * blocksizes. 4096 is the maximum blocksize because it is
  477. * the minimum clustersize.
  478. */
  479. status = -EINVAL;
  480. for (blksize = *sector_size;
  481. blksize <= OCFS2_MAX_BLOCKSIZE;
  482. blksize <<= 1) {
  483. tmpstat = ocfs2_get_sector(sb, bh,
  484. OCFS2_SUPER_BLOCK_BLKNO,
  485. blksize);
  486. if (tmpstat < 0) {
  487. status = tmpstat;
  488. mlog_errno(status);
  489. goto bail;
  490. }
  491. di = (struct ocfs2_dinode *) (*bh)->b_data;
  492. status = ocfs2_verify_volume(di, *bh, blksize);
  493. if (status >= 0)
  494. goto bail;
  495. brelse(*bh);
  496. *bh = NULL;
  497. if (status != -EAGAIN)
  498. break;
  499. }
  500. bail:
  501. return status;
  502. }
  503. static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
  504. {
  505. if (ocfs2_mount_local(osb)) {
  506. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  507. mlog(ML_ERROR, "Cannot heartbeat on a locally "
  508. "mounted device.\n");
  509. return -EINVAL;
  510. }
  511. }
  512. if (ocfs2_userspace_stack(osb)) {
  513. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  514. mlog(ML_ERROR, "Userspace stack expected, but "
  515. "o2cb heartbeat arguments passed to mount\n");
  516. return -EINVAL;
  517. }
  518. }
  519. if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
  520. if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
  521. !ocfs2_userspace_stack(osb)) {
  522. mlog(ML_ERROR, "Heartbeat has to be started to mount "
  523. "a read-write clustered device.\n");
  524. return -EINVAL;
  525. }
  526. }
  527. return 0;
  528. }
  529. /*
  530. * If we're using a userspace stack, mount should have passed
  531. * a name that matches the disk. If not, mount should not
  532. * have passed a stack.
  533. */
  534. static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
  535. struct mount_options *mopt)
  536. {
  537. if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
  538. mlog(ML_ERROR,
  539. "cluster stack passed to mount, but this filesystem "
  540. "does not support it\n");
  541. return -EINVAL;
  542. }
  543. if (ocfs2_userspace_stack(osb) &&
  544. strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
  545. OCFS2_STACK_LABEL_LEN)) {
  546. mlog(ML_ERROR,
  547. "cluster stack passed to mount (\"%s\") does not "
  548. "match the filesystem (\"%s\")\n",
  549. mopt->cluster_stack,
  550. osb->osb_cluster_stack);
  551. return -EINVAL;
  552. }
  553. return 0;
  554. }
  555. static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
  556. {
  557. struct dentry *root;
  558. int status, sector_size;
  559. struct mount_options parsed_options;
  560. struct inode *inode = NULL;
  561. struct ocfs2_super *osb = NULL;
  562. struct buffer_head *bh = NULL;
  563. char nodestr[8];
  564. mlog_entry("%p, %p, %i", sb, data, silent);
  565. if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
  566. status = -EINVAL;
  567. goto read_super_error;
  568. }
  569. /* probe for superblock */
  570. status = ocfs2_sb_probe(sb, &bh, &sector_size);
  571. if (status < 0) {
  572. mlog(ML_ERROR, "superblock probe failed!\n");
  573. goto read_super_error;
  574. }
  575. status = ocfs2_initialize_super(sb, bh, sector_size);
  576. osb = OCFS2_SB(sb);
  577. if (status < 0) {
  578. mlog_errno(status);
  579. goto read_super_error;
  580. }
  581. brelse(bh);
  582. bh = NULL;
  583. if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
  584. parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  585. osb->s_mount_opt = parsed_options.mount_opt;
  586. osb->s_atime_quantum = parsed_options.atime_quantum;
  587. osb->preferred_slot = parsed_options.slot;
  588. osb->osb_commit_interval = parsed_options.commit_interval;
  589. osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
  590. osb->local_alloc_bits = osb->local_alloc_default_bits;
  591. status = ocfs2_verify_userspace_stack(osb, &parsed_options);
  592. if (status)
  593. goto read_super_error;
  594. sb->s_magic = OCFS2_SUPER_MAGIC;
  595. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  596. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  597. /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
  598. * heartbeat=none */
  599. if (bdev_read_only(sb->s_bdev)) {
  600. if (!(sb->s_flags & MS_RDONLY)) {
  601. status = -EACCES;
  602. mlog(ML_ERROR, "Readonly device detected but readonly "
  603. "mount was not specified.\n");
  604. goto read_super_error;
  605. }
  606. /* You should not be able to start a local heartbeat
  607. * on a readonly device. */
  608. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  609. status = -EROFS;
  610. mlog(ML_ERROR, "Local heartbeat specified on readonly "
  611. "device.\n");
  612. goto read_super_error;
  613. }
  614. status = ocfs2_check_journals_nolocks(osb);
  615. if (status < 0) {
  616. if (status == -EROFS)
  617. mlog(ML_ERROR, "Recovery required on readonly "
  618. "file system, but write access is "
  619. "unavailable.\n");
  620. else
  621. mlog_errno(status);
  622. goto read_super_error;
  623. }
  624. ocfs2_set_ro_flag(osb, 1);
  625. printk(KERN_NOTICE "Readonly device detected. No cluster "
  626. "services will be utilized for this mount. Recovery "
  627. "will be skipped.\n");
  628. }
  629. if (!ocfs2_is_hard_readonly(osb)) {
  630. if (sb->s_flags & MS_RDONLY)
  631. ocfs2_set_ro_flag(osb, 0);
  632. }
  633. status = ocfs2_verify_heartbeat(osb);
  634. if (status < 0) {
  635. mlog_errno(status);
  636. goto read_super_error;
  637. }
  638. osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
  639. ocfs2_debugfs_root);
  640. if (!osb->osb_debug_root) {
  641. status = -EINVAL;
  642. mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
  643. goto read_super_error;
  644. }
  645. status = ocfs2_mount_volume(sb);
  646. if (osb->root_inode)
  647. inode = igrab(osb->root_inode);
  648. if (status < 0)
  649. goto read_super_error;
  650. if (!inode) {
  651. status = -EIO;
  652. mlog_errno(status);
  653. goto read_super_error;
  654. }
  655. root = d_alloc_root(inode);
  656. if (!root) {
  657. status = -ENOMEM;
  658. mlog_errno(status);
  659. goto read_super_error;
  660. }
  661. sb->s_root = root;
  662. ocfs2_complete_mount_recovery(osb);
  663. if (ocfs2_mount_local(osb))
  664. snprintf(nodestr, sizeof(nodestr), "local");
  665. else
  666. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  667. printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
  668. "with %s data mode.\n",
  669. osb->dev_str, nodestr, osb->slot_num,
  670. osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
  671. "ordered");
  672. atomic_set(&osb->vol_state, VOLUME_MOUNTED);
  673. wake_up(&osb->osb_mount_event);
  674. mlog_exit(status);
  675. return status;
  676. read_super_error:
  677. brelse(bh);
  678. if (inode)
  679. iput(inode);
  680. if (osb) {
  681. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  682. wake_up(&osb->osb_mount_event);
  683. ocfs2_dismount_volume(sb, 1);
  684. }
  685. mlog_exit(status);
  686. return status;
  687. }
  688. static int ocfs2_get_sb(struct file_system_type *fs_type,
  689. int flags,
  690. const char *dev_name,
  691. void *data,
  692. struct vfsmount *mnt)
  693. {
  694. return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
  695. mnt);
  696. }
  697. static struct file_system_type ocfs2_fs_type = {
  698. .owner = THIS_MODULE,
  699. .name = "ocfs2",
  700. .get_sb = ocfs2_get_sb, /* is this called when we mount
  701. * the fs? */
  702. .kill_sb = kill_block_super, /* set to the generic one
  703. * right now, but do we
  704. * need to change that? */
  705. .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
  706. .next = NULL
  707. };
  708. static int ocfs2_parse_options(struct super_block *sb,
  709. char *options,
  710. struct mount_options *mopt,
  711. int is_remount)
  712. {
  713. int status;
  714. char *p;
  715. mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
  716. options ? options : "(none)");
  717. mopt->commit_interval = 0;
  718. mopt->mount_opt = 0;
  719. mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  720. mopt->slot = OCFS2_INVALID_SLOT;
  721. mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
  722. mopt->cluster_stack[0] = '\0';
  723. if (!options) {
  724. status = 1;
  725. goto bail;
  726. }
  727. while ((p = strsep(&options, ",")) != NULL) {
  728. int token, option;
  729. substring_t args[MAX_OPT_ARGS];
  730. if (!*p)
  731. continue;
  732. token = match_token(p, tokens, args);
  733. switch (token) {
  734. case Opt_hb_local:
  735. mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
  736. break;
  737. case Opt_hb_none:
  738. mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
  739. break;
  740. case Opt_barrier:
  741. if (match_int(&args[0], &option)) {
  742. status = 0;
  743. goto bail;
  744. }
  745. if (option)
  746. mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
  747. else
  748. mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
  749. break;
  750. case Opt_intr:
  751. mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
  752. break;
  753. case Opt_nointr:
  754. mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
  755. break;
  756. case Opt_err_panic:
  757. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  758. break;
  759. case Opt_err_ro:
  760. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
  761. break;
  762. case Opt_data_ordered:
  763. mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
  764. break;
  765. case Opt_data_writeback:
  766. mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
  767. break;
  768. case Opt_user_xattr:
  769. mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
  770. break;
  771. case Opt_nouser_xattr:
  772. mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
  773. break;
  774. case Opt_atime_quantum:
  775. if (match_int(&args[0], &option)) {
  776. status = 0;
  777. goto bail;
  778. }
  779. if (option >= 0)
  780. mopt->atime_quantum = option;
  781. break;
  782. case Opt_slot:
  783. option = 0;
  784. if (match_int(&args[0], &option)) {
  785. status = 0;
  786. goto bail;
  787. }
  788. if (option)
  789. mopt->slot = (s16)option;
  790. break;
  791. case Opt_commit:
  792. option = 0;
  793. if (match_int(&args[0], &option)) {
  794. status = 0;
  795. goto bail;
  796. }
  797. if (option < 0)
  798. return 0;
  799. if (option == 0)
  800. option = JBD2_DEFAULT_MAX_COMMIT_AGE;
  801. mopt->commit_interval = HZ * option;
  802. break;
  803. case Opt_localalloc:
  804. option = 0;
  805. if (match_int(&args[0], &option)) {
  806. status = 0;
  807. goto bail;
  808. }
  809. if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
  810. mopt->localalloc_opt = option;
  811. break;
  812. case Opt_localflocks:
  813. /*
  814. * Changing this during remount could race
  815. * flock() requests, or "unbalance" existing
  816. * ones (e.g., a lock is taken in one mode but
  817. * dropped in the other). If users care enough
  818. * to flip locking modes during remount, we
  819. * could add a "local" flag to individual
  820. * flock structures for proper tracking of
  821. * state.
  822. */
  823. if (!is_remount)
  824. mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
  825. break;
  826. case Opt_stack:
  827. /* Check both that the option we were passed
  828. * is of the right length and that it is a proper
  829. * string of the right length.
  830. */
  831. if (((args[0].to - args[0].from) !=
  832. OCFS2_STACK_LABEL_LEN) ||
  833. (strnlen(args[0].from,
  834. OCFS2_STACK_LABEL_LEN) !=
  835. OCFS2_STACK_LABEL_LEN)) {
  836. mlog(ML_ERROR,
  837. "Invalid cluster_stack option\n");
  838. status = 0;
  839. goto bail;
  840. }
  841. memcpy(mopt->cluster_stack, args[0].from,
  842. OCFS2_STACK_LABEL_LEN);
  843. mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  844. break;
  845. case Opt_inode64:
  846. mopt->mount_opt |= OCFS2_MOUNT_INODE64;
  847. break;
  848. #ifdef CONFIG_OCFS2_FS_POSIX_ACL
  849. case Opt_acl:
  850. mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  851. break;
  852. case Opt_noacl:
  853. mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  854. break;
  855. #else
  856. case Opt_acl:
  857. case Opt_noacl:
  858. printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
  859. break;
  860. #endif
  861. default:
  862. mlog(ML_ERROR,
  863. "Unrecognized mount option \"%s\" "
  864. "or missing value\n", p);
  865. status = 0;
  866. goto bail;
  867. }
  868. }
  869. status = 1;
  870. bail:
  871. mlog_exit(status);
  872. return status;
  873. }
  874. static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  875. {
  876. struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
  877. unsigned long opts = osb->s_mount_opt;
  878. unsigned int local_alloc_megs;
  879. if (opts & OCFS2_MOUNT_HB_LOCAL)
  880. seq_printf(s, ",_netdev,heartbeat=local");
  881. else
  882. seq_printf(s, ",heartbeat=none");
  883. if (opts & OCFS2_MOUNT_NOINTR)
  884. seq_printf(s, ",nointr");
  885. if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
  886. seq_printf(s, ",data=writeback");
  887. else
  888. seq_printf(s, ",data=ordered");
  889. if (opts & OCFS2_MOUNT_BARRIER)
  890. seq_printf(s, ",barrier=1");
  891. if (opts & OCFS2_MOUNT_ERRORS_PANIC)
  892. seq_printf(s, ",errors=panic");
  893. else
  894. seq_printf(s, ",errors=remount-ro");
  895. if (osb->preferred_slot != OCFS2_INVALID_SLOT)
  896. seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
  897. if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
  898. seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
  899. if (osb->osb_commit_interval)
  900. seq_printf(s, ",commit=%u",
  901. (unsigned) (osb->osb_commit_interval / HZ));
  902. local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
  903. if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
  904. seq_printf(s, ",localalloc=%d", local_alloc_megs);
  905. if (opts & OCFS2_MOUNT_LOCALFLOCKS)
  906. seq_printf(s, ",localflocks,");
  907. if (osb->osb_cluster_stack[0])
  908. seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
  909. osb->osb_cluster_stack);
  910. if (opts & OCFS2_MOUNT_NOUSERXATTR)
  911. seq_printf(s, ",nouser_xattr");
  912. else
  913. seq_printf(s, ",user_xattr");
  914. if (opts & OCFS2_MOUNT_INODE64)
  915. seq_printf(s, ",inode64");
  916. #ifdef CONFIG_OCFS2_FS_POSIX_ACL
  917. if (opts & OCFS2_MOUNT_POSIX_ACL)
  918. seq_printf(s, ",acl");
  919. else
  920. seq_printf(s, ",noacl");
  921. #endif
  922. return 0;
  923. }
  924. static int __init ocfs2_init(void)
  925. {
  926. int status;
  927. mlog_entry_void();
  928. ocfs2_print_version();
  929. status = init_ocfs2_uptodate_cache();
  930. if (status < 0) {
  931. mlog_errno(status);
  932. goto leave;
  933. }
  934. status = ocfs2_initialize_mem_caches();
  935. if (status < 0) {
  936. mlog_errno(status);
  937. goto leave;
  938. }
  939. ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
  940. if (!ocfs2_wq) {
  941. status = -ENOMEM;
  942. goto leave;
  943. }
  944. ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
  945. if (!ocfs2_debugfs_root) {
  946. status = -EFAULT;
  947. mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
  948. }
  949. ocfs2_set_locking_protocol();
  950. leave:
  951. if (status < 0) {
  952. ocfs2_free_mem_caches();
  953. exit_ocfs2_uptodate_cache();
  954. }
  955. mlog_exit(status);
  956. if (status >= 0) {
  957. return register_filesystem(&ocfs2_fs_type);
  958. } else
  959. return -1;
  960. }
  961. static void __exit ocfs2_exit(void)
  962. {
  963. mlog_entry_void();
  964. if (ocfs2_wq) {
  965. flush_workqueue(ocfs2_wq);
  966. destroy_workqueue(ocfs2_wq);
  967. }
  968. debugfs_remove(ocfs2_debugfs_root);
  969. ocfs2_free_mem_caches();
  970. unregister_filesystem(&ocfs2_fs_type);
  971. exit_ocfs2_uptodate_cache();
  972. mlog_exit_void();
  973. }
  974. static void ocfs2_put_super(struct super_block *sb)
  975. {
  976. mlog_entry("(0x%p)\n", sb);
  977. ocfs2_sync_blockdev(sb);
  978. ocfs2_dismount_volume(sb, 0);
  979. mlog_exit_void();
  980. }
  981. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
  982. {
  983. struct ocfs2_super *osb;
  984. u32 numbits, freebits;
  985. int status;
  986. struct ocfs2_dinode *bm_lock;
  987. struct buffer_head *bh = NULL;
  988. struct inode *inode = NULL;
  989. mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
  990. osb = OCFS2_SB(dentry->d_sb);
  991. inode = ocfs2_get_system_file_inode(osb,
  992. GLOBAL_BITMAP_SYSTEM_INODE,
  993. OCFS2_INVALID_SLOT);
  994. if (!inode) {
  995. mlog(ML_ERROR, "failed to get bitmap inode\n");
  996. status = -EIO;
  997. goto bail;
  998. }
  999. status = ocfs2_inode_lock(inode, &bh, 0);
  1000. if (status < 0) {
  1001. mlog_errno(status);
  1002. goto bail;
  1003. }
  1004. bm_lock = (struct ocfs2_dinode *) bh->b_data;
  1005. numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
  1006. freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
  1007. buf->f_type = OCFS2_SUPER_MAGIC;
  1008. buf->f_bsize = dentry->d_sb->s_blocksize;
  1009. buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
  1010. buf->f_blocks = ((sector_t) numbits) *
  1011. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1012. buf->f_bfree = ((sector_t) freebits) *
  1013. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1014. buf->f_bavail = buf->f_bfree;
  1015. buf->f_files = numbits;
  1016. buf->f_ffree = freebits;
  1017. brelse(bh);
  1018. ocfs2_inode_unlock(inode, 0);
  1019. status = 0;
  1020. bail:
  1021. if (inode)
  1022. iput(inode);
  1023. mlog_exit(status);
  1024. return status;
  1025. }
  1026. static void ocfs2_inode_init_once(void *data)
  1027. {
  1028. struct ocfs2_inode_info *oi = data;
  1029. oi->ip_flags = 0;
  1030. oi->ip_open_count = 0;
  1031. spin_lock_init(&oi->ip_lock);
  1032. ocfs2_extent_map_init(&oi->vfs_inode);
  1033. INIT_LIST_HEAD(&oi->ip_io_markers);
  1034. oi->ip_created_trans = 0;
  1035. oi->ip_last_trans = 0;
  1036. oi->ip_dir_start_lookup = 0;
  1037. init_rwsem(&oi->ip_alloc_sem);
  1038. init_rwsem(&oi->ip_xattr_sem);
  1039. mutex_init(&oi->ip_io_mutex);
  1040. oi->ip_blkno = 0ULL;
  1041. oi->ip_clusters = 0;
  1042. ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
  1043. ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
  1044. ocfs2_lock_res_init_once(&oi->ip_open_lockres);
  1045. ocfs2_metadata_cache_init(&oi->vfs_inode);
  1046. inode_init_once(&oi->vfs_inode);
  1047. }
  1048. static int ocfs2_initialize_mem_caches(void)
  1049. {
  1050. ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
  1051. sizeof(struct ocfs2_inode_info),
  1052. 0,
  1053. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1054. SLAB_MEM_SPREAD),
  1055. ocfs2_inode_init_once);
  1056. if (!ocfs2_inode_cachep)
  1057. return -ENOMEM;
  1058. return 0;
  1059. }
  1060. static void ocfs2_free_mem_caches(void)
  1061. {
  1062. if (ocfs2_inode_cachep)
  1063. kmem_cache_destroy(ocfs2_inode_cachep);
  1064. ocfs2_inode_cachep = NULL;
  1065. }
  1066. static int ocfs2_get_sector(struct super_block *sb,
  1067. struct buffer_head **bh,
  1068. int block,
  1069. int sect_size)
  1070. {
  1071. if (!sb_set_blocksize(sb, sect_size)) {
  1072. mlog(ML_ERROR, "unable to set blocksize\n");
  1073. return -EIO;
  1074. }
  1075. *bh = sb_getblk(sb, block);
  1076. if (!*bh) {
  1077. mlog_errno(-EIO);
  1078. return -EIO;
  1079. }
  1080. lock_buffer(*bh);
  1081. if (!buffer_dirty(*bh))
  1082. clear_buffer_uptodate(*bh);
  1083. unlock_buffer(*bh);
  1084. ll_rw_block(READ, 1, bh);
  1085. wait_on_buffer(*bh);
  1086. return 0;
  1087. }
  1088. static int ocfs2_mount_volume(struct super_block *sb)
  1089. {
  1090. int status = 0;
  1091. int unlock_super = 0;
  1092. struct ocfs2_super *osb = OCFS2_SB(sb);
  1093. mlog_entry_void();
  1094. if (ocfs2_is_hard_readonly(osb))
  1095. goto leave;
  1096. status = ocfs2_dlm_init(osb);
  1097. if (status < 0) {
  1098. mlog_errno(status);
  1099. goto leave;
  1100. }
  1101. status = ocfs2_super_lock(osb, 1);
  1102. if (status < 0) {
  1103. mlog_errno(status);
  1104. goto leave;
  1105. }
  1106. unlock_super = 1;
  1107. /* This will load up the node map and add ourselves to it. */
  1108. status = ocfs2_find_slot(osb);
  1109. if (status < 0) {
  1110. mlog_errno(status);
  1111. goto leave;
  1112. }
  1113. /* load all node-local system inodes */
  1114. status = ocfs2_init_local_system_inodes(osb);
  1115. if (status < 0) {
  1116. mlog_errno(status);
  1117. goto leave;
  1118. }
  1119. status = ocfs2_check_volume(osb);
  1120. if (status < 0) {
  1121. mlog_errno(status);
  1122. goto leave;
  1123. }
  1124. status = ocfs2_truncate_log_init(osb);
  1125. if (status < 0) {
  1126. mlog_errno(status);
  1127. goto leave;
  1128. }
  1129. if (ocfs2_mount_local(osb))
  1130. goto leave;
  1131. leave:
  1132. if (unlock_super)
  1133. ocfs2_super_unlock(osb, 1);
  1134. mlog_exit(status);
  1135. return status;
  1136. }
  1137. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
  1138. {
  1139. int tmp, hangup_needed = 0;
  1140. struct ocfs2_super *osb = NULL;
  1141. char nodestr[8];
  1142. mlog_entry("(0x%p)\n", sb);
  1143. BUG_ON(!sb);
  1144. osb = OCFS2_SB(sb);
  1145. BUG_ON(!osb);
  1146. ocfs2_shutdown_local_alloc(osb);
  1147. ocfs2_truncate_log_shutdown(osb);
  1148. /* This will disable recovery and flush any recovery work. */
  1149. ocfs2_recovery_exit(osb);
  1150. ocfs2_journal_shutdown(osb);
  1151. ocfs2_sync_blockdev(sb);
  1152. /* No cluster connection means we've failed during mount, so skip
  1153. * all the steps which depended on that to complete. */
  1154. if (osb->cconn) {
  1155. tmp = ocfs2_super_lock(osb, 1);
  1156. if (tmp < 0) {
  1157. mlog_errno(tmp);
  1158. return;
  1159. }
  1160. }
  1161. if (osb->slot_num != OCFS2_INVALID_SLOT)
  1162. ocfs2_put_slot(osb);
  1163. if (osb->cconn)
  1164. ocfs2_super_unlock(osb, 1);
  1165. ocfs2_release_system_inodes(osb);
  1166. /*
  1167. * If we're dismounting due to mount error, mount.ocfs2 will clean
  1168. * up heartbeat. If we're a local mount, there is no heartbeat.
  1169. * If we failed before we got a uuid_str yet, we can't stop
  1170. * heartbeat. Otherwise, do it.
  1171. */
  1172. if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
  1173. hangup_needed = 1;
  1174. if (osb->cconn)
  1175. ocfs2_dlm_shutdown(osb, hangup_needed);
  1176. debugfs_remove(osb->osb_debug_root);
  1177. if (hangup_needed)
  1178. ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
  1179. atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
  1180. if (ocfs2_mount_local(osb))
  1181. snprintf(nodestr, sizeof(nodestr), "local");
  1182. else
  1183. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1184. printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
  1185. osb->dev_str, nodestr);
  1186. ocfs2_delete_osb(osb);
  1187. kfree(osb);
  1188. sb->s_dev = 0;
  1189. sb->s_fs_info = NULL;
  1190. }
  1191. static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
  1192. unsigned uuid_bytes)
  1193. {
  1194. int i, ret;
  1195. char *ptr;
  1196. BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
  1197. osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
  1198. if (osb->uuid_str == NULL)
  1199. return -ENOMEM;
  1200. for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
  1201. /* print with null */
  1202. ret = snprintf(ptr, 3, "%02X", uuid[i]);
  1203. if (ret != 2) /* drop super cleans up */
  1204. return -EINVAL;
  1205. /* then only advance past the last char */
  1206. ptr += 2;
  1207. }
  1208. return 0;
  1209. }
  1210. static int ocfs2_initialize_super(struct super_block *sb,
  1211. struct buffer_head *bh,
  1212. int sector_size)
  1213. {
  1214. int status;
  1215. int i, cbits, bbits;
  1216. struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
  1217. struct inode *inode = NULL;
  1218. struct ocfs2_journal *journal;
  1219. __le32 uuid_net_key;
  1220. struct ocfs2_super *osb;
  1221. mlog_entry_void();
  1222. osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
  1223. if (!osb) {
  1224. status = -ENOMEM;
  1225. mlog_errno(status);
  1226. goto bail;
  1227. }
  1228. sb->s_fs_info = osb;
  1229. sb->s_op = &ocfs2_sops;
  1230. sb->s_export_op = &ocfs2_export_ops;
  1231. sb->s_xattr = ocfs2_xattr_handlers;
  1232. sb->s_time_gran = 1;
  1233. sb->s_flags |= MS_NOATIME;
  1234. /* this is needed to support O_LARGEFILE */
  1235. cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1236. bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
  1237. sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
  1238. osb->sb = sb;
  1239. /* Save off for ocfs2_rw_direct */
  1240. osb->s_sectsize_bits = blksize_bits(sector_size);
  1241. BUG_ON(!osb->s_sectsize_bits);
  1242. spin_lock_init(&osb->dc_task_lock);
  1243. init_waitqueue_head(&osb->dc_event);
  1244. osb->dc_work_sequence = 0;
  1245. osb->dc_wake_sequence = 0;
  1246. INIT_LIST_HEAD(&osb->blocked_lock_list);
  1247. osb->blocked_lock_count = 0;
  1248. spin_lock_init(&osb->osb_lock);
  1249. ocfs2_init_inode_steal_slot(osb);
  1250. atomic_set(&osb->alloc_stats.moves, 0);
  1251. atomic_set(&osb->alloc_stats.local_data, 0);
  1252. atomic_set(&osb->alloc_stats.bitmap_data, 0);
  1253. atomic_set(&osb->alloc_stats.bg_allocs, 0);
  1254. atomic_set(&osb->alloc_stats.bg_extends, 0);
  1255. ocfs2_init_node_maps(osb);
  1256. snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
  1257. MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
  1258. status = ocfs2_recovery_init(osb);
  1259. if (status) {
  1260. mlog(ML_ERROR, "Unable to initialize recovery state\n");
  1261. mlog_errno(status);
  1262. goto bail;
  1263. }
  1264. init_waitqueue_head(&osb->checkpoint_event);
  1265. atomic_set(&osb->needs_checkpoint, 0);
  1266. osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1267. osb->slot_num = OCFS2_INVALID_SLOT;
  1268. osb->s_xattr_inline_size = le16_to_cpu(
  1269. di->id2.i_super.s_xattr_inline_size);
  1270. osb->local_alloc_state = OCFS2_LA_UNUSED;
  1271. osb->local_alloc_bh = NULL;
  1272. INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
  1273. init_waitqueue_head(&osb->osb_mount_event);
  1274. osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
  1275. if (!osb->vol_label) {
  1276. mlog(ML_ERROR, "unable to alloc vol label\n");
  1277. status = -ENOMEM;
  1278. goto bail;
  1279. }
  1280. osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
  1281. if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
  1282. mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
  1283. osb->max_slots);
  1284. status = -EINVAL;
  1285. goto bail;
  1286. }
  1287. mlog(0, "max_slots for this device: %u\n", osb->max_slots);
  1288. osb->slot_recovery_generations =
  1289. kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
  1290. GFP_KERNEL);
  1291. if (!osb->slot_recovery_generations) {
  1292. status = -ENOMEM;
  1293. mlog_errno(status);
  1294. goto bail;
  1295. }
  1296. init_waitqueue_head(&osb->osb_wipe_event);
  1297. osb->osb_orphan_wipes = kcalloc(osb->max_slots,
  1298. sizeof(*osb->osb_orphan_wipes),
  1299. GFP_KERNEL);
  1300. if (!osb->osb_orphan_wipes) {
  1301. status = -ENOMEM;
  1302. mlog_errno(status);
  1303. goto bail;
  1304. }
  1305. osb->s_feature_compat =
  1306. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
  1307. osb->s_feature_ro_compat =
  1308. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
  1309. osb->s_feature_incompat =
  1310. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
  1311. if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
  1312. mlog(ML_ERROR, "couldn't mount because of unsupported "
  1313. "optional features (%x).\n", i);
  1314. status = -EINVAL;
  1315. goto bail;
  1316. }
  1317. if (!(osb->sb->s_flags & MS_RDONLY) &&
  1318. (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
  1319. mlog(ML_ERROR, "couldn't mount RDWR because of "
  1320. "unsupported optional features (%x).\n", i);
  1321. status = -EINVAL;
  1322. goto bail;
  1323. }
  1324. if (ocfs2_userspace_stack(osb)) {
  1325. memcpy(osb->osb_cluster_stack,
  1326. OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
  1327. OCFS2_STACK_LABEL_LEN);
  1328. osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1329. if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
  1330. mlog(ML_ERROR,
  1331. "couldn't mount because of an invalid "
  1332. "cluster stack label (%s) \n",
  1333. osb->osb_cluster_stack);
  1334. status = -EINVAL;
  1335. goto bail;
  1336. }
  1337. } else {
  1338. /* The empty string is identical with classic tools that
  1339. * don't know about s_cluster_info. */
  1340. osb->osb_cluster_stack[0] = '\0';
  1341. }
  1342. get_random_bytes(&osb->s_next_generation, sizeof(u32));
  1343. /* FIXME
  1344. * This should be done in ocfs2_journal_init(), but unknown
  1345. * ordering issues will cause the filesystem to crash.
  1346. * If anyone wants to figure out what part of the code
  1347. * refers to osb->journal before ocfs2_journal_init() is run,
  1348. * be my guest.
  1349. */
  1350. /* initialize our journal structure */
  1351. journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
  1352. if (!journal) {
  1353. mlog(ML_ERROR, "unable to alloc journal\n");
  1354. status = -ENOMEM;
  1355. goto bail;
  1356. }
  1357. osb->journal = journal;
  1358. journal->j_osb = osb;
  1359. atomic_set(&journal->j_num_trans, 0);
  1360. init_rwsem(&journal->j_trans_barrier);
  1361. init_waitqueue_head(&journal->j_checkpointed);
  1362. spin_lock_init(&journal->j_lock);
  1363. journal->j_trans_id = (unsigned long) 1;
  1364. INIT_LIST_HEAD(&journal->j_la_cleanups);
  1365. INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
  1366. journal->j_state = OCFS2_JOURNAL_FREE;
  1367. /* get some pseudo constants for clustersize bits */
  1368. osb->s_clustersize_bits =
  1369. le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1370. osb->s_clustersize = 1 << osb->s_clustersize_bits;
  1371. mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
  1372. if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
  1373. osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
  1374. mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
  1375. osb->s_clustersize);
  1376. status = -EINVAL;
  1377. goto bail;
  1378. }
  1379. if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
  1380. > (u32)~0UL) {
  1381. mlog(ML_ERROR, "Volume might try to write to blocks beyond "
  1382. "what jbd can address in 32 bits.\n");
  1383. status = -EINVAL;
  1384. goto bail;
  1385. }
  1386. if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
  1387. sizeof(di->id2.i_super.s_uuid))) {
  1388. mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
  1389. status = -ENOMEM;
  1390. goto bail;
  1391. }
  1392. memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
  1393. strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
  1394. osb->vol_label[63] = '\0';
  1395. osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
  1396. osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
  1397. osb->first_cluster_group_blkno =
  1398. le64_to_cpu(di->id2.i_super.s_first_cluster_group);
  1399. osb->fs_generation = le32_to_cpu(di->i_fs_generation);
  1400. osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1401. mlog(0, "vol_label: %s\n", osb->vol_label);
  1402. mlog(0, "uuid: %s\n", osb->uuid_str);
  1403. mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
  1404. (unsigned long long)osb->root_blkno,
  1405. (unsigned long long)osb->system_dir_blkno);
  1406. osb->osb_dlm_debug = ocfs2_new_dlm_debug();
  1407. if (!osb->osb_dlm_debug) {
  1408. status = -ENOMEM;
  1409. mlog_errno(status);
  1410. goto bail;
  1411. }
  1412. atomic_set(&osb->vol_state, VOLUME_INIT);
  1413. /* load root, system_dir, and all global system inodes */
  1414. status = ocfs2_init_global_system_inodes(osb);
  1415. if (status < 0) {
  1416. mlog_errno(status);
  1417. goto bail;
  1418. }
  1419. /*
  1420. * global bitmap
  1421. */
  1422. inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
  1423. OCFS2_INVALID_SLOT);
  1424. if (!inode) {
  1425. status = -EINVAL;
  1426. mlog_errno(status);
  1427. goto bail;
  1428. }
  1429. osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
  1430. iput(inode);
  1431. osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
  1432. status = ocfs2_init_slot_info(osb);
  1433. if (status < 0) {
  1434. mlog_errno(status);
  1435. goto bail;
  1436. }
  1437. bail:
  1438. mlog_exit(status);
  1439. return status;
  1440. }
  1441. /*
  1442. * will return: -EAGAIN if it is ok to keep searching for superblocks
  1443. * -EINVAL if there is a bad superblock
  1444. * 0 on success
  1445. */
  1446. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  1447. struct buffer_head *bh,
  1448. u32 blksz)
  1449. {
  1450. int status = -EAGAIN;
  1451. mlog_entry_void();
  1452. if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
  1453. strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
  1454. status = -EINVAL;
  1455. if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
  1456. mlog(ML_ERROR, "found superblock with incorrect block "
  1457. "size: found %u, should be %u\n",
  1458. 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
  1459. blksz);
  1460. } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
  1461. OCFS2_MAJOR_REV_LEVEL ||
  1462. le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
  1463. OCFS2_MINOR_REV_LEVEL) {
  1464. mlog(ML_ERROR, "found superblock with bad version: "
  1465. "found %u.%u, should be %u.%u\n",
  1466. le16_to_cpu(di->id2.i_super.s_major_rev_level),
  1467. le16_to_cpu(di->id2.i_super.s_minor_rev_level),
  1468. OCFS2_MAJOR_REV_LEVEL,
  1469. OCFS2_MINOR_REV_LEVEL);
  1470. } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
  1471. mlog(ML_ERROR, "bad block number on superblock: "
  1472. "found %llu, should be %llu\n",
  1473. (unsigned long long)le64_to_cpu(di->i_blkno),
  1474. (unsigned long long)bh->b_blocknr);
  1475. } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
  1476. le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
  1477. mlog(ML_ERROR, "bad cluster size found: %u\n",
  1478. 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
  1479. } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
  1480. mlog(ML_ERROR, "bad root_blkno: 0\n");
  1481. } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
  1482. mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
  1483. } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
  1484. mlog(ML_ERROR,
  1485. "Superblock slots found greater than file system "
  1486. "maximum: found %u, max %u\n",
  1487. le16_to_cpu(di->id2.i_super.s_max_slots),
  1488. OCFS2_MAX_SLOTS);
  1489. } else {
  1490. /* found it! */
  1491. status = 0;
  1492. }
  1493. }
  1494. mlog_exit(status);
  1495. return status;
  1496. }
  1497. static int ocfs2_check_volume(struct ocfs2_super *osb)
  1498. {
  1499. int status;
  1500. int dirty;
  1501. int local;
  1502. struct ocfs2_dinode *local_alloc = NULL; /* only used if we
  1503. * recover
  1504. * ourselves. */
  1505. mlog_entry_void();
  1506. /* Init our journal object. */
  1507. status = ocfs2_journal_init(osb->journal, &dirty);
  1508. if (status < 0) {
  1509. mlog(ML_ERROR, "Could not initialize journal!\n");
  1510. goto finally;
  1511. }
  1512. /* If the journal was unmounted cleanly then we don't want to
  1513. * recover anything. Otherwise, journal_load will do that
  1514. * dirty work for us :) */
  1515. if (!dirty) {
  1516. status = ocfs2_journal_wipe(osb->journal, 0);
  1517. if (status < 0) {
  1518. mlog_errno(status);
  1519. goto finally;
  1520. }
  1521. } else {
  1522. mlog(ML_NOTICE, "File system was not unmounted cleanly, "
  1523. "recovering volume.\n");
  1524. }
  1525. local = ocfs2_mount_local(osb);
  1526. /* will play back anything left in the journal. */
  1527. status = ocfs2_journal_load(osb->journal, local, dirty);
  1528. if (status < 0) {
  1529. mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
  1530. goto finally;
  1531. }
  1532. if (dirty) {
  1533. /* recover my local alloc if we didn't unmount cleanly. */
  1534. status = ocfs2_begin_local_alloc_recovery(osb,
  1535. osb->slot_num,
  1536. &local_alloc);
  1537. if (status < 0) {
  1538. mlog_errno(status);
  1539. goto finally;
  1540. }
  1541. /* we complete the recovery process after we've marked
  1542. * ourselves as mounted. */
  1543. }
  1544. mlog(0, "Journal loaded.\n");
  1545. status = ocfs2_load_local_alloc(osb);
  1546. if (status < 0) {
  1547. mlog_errno(status);
  1548. goto finally;
  1549. }
  1550. if (dirty) {
  1551. /* Recovery will be completed after we've mounted the
  1552. * rest of the volume. */
  1553. osb->dirty = 1;
  1554. osb->local_alloc_copy = local_alloc;
  1555. local_alloc = NULL;
  1556. }
  1557. /* go through each journal, trylock it and if you get the
  1558. * lock, and it's marked as dirty, set the bit in the recover
  1559. * map and launch a recovery thread for it. */
  1560. status = ocfs2_mark_dead_nodes(osb);
  1561. if (status < 0)
  1562. mlog_errno(status);
  1563. finally:
  1564. if (local_alloc)
  1565. kfree(local_alloc);
  1566. mlog_exit(status);
  1567. return status;
  1568. }
  1569. /*
  1570. * The routine gets called from dismount or close whenever a dismount on
  1571. * volume is requested and the osb open count becomes 1.
  1572. * It will remove the osb from the global list and also free up all the
  1573. * initialized resources and fileobject.
  1574. */
  1575. static void ocfs2_delete_osb(struct ocfs2_super *osb)
  1576. {
  1577. mlog_entry_void();
  1578. /* This function assumes that the caller has the main osb resource */
  1579. ocfs2_free_slot_info(osb);
  1580. kfree(osb->osb_orphan_wipes);
  1581. kfree(osb->slot_recovery_generations);
  1582. /* FIXME
  1583. * This belongs in journal shutdown, but because we have to
  1584. * allocate osb->journal at the start of ocfs2_initalize_osb(),
  1585. * we free it here.
  1586. */
  1587. kfree(osb->journal);
  1588. if (osb->local_alloc_copy)
  1589. kfree(osb->local_alloc_copy);
  1590. kfree(osb->uuid_str);
  1591. ocfs2_put_dlm_debug(osb->osb_dlm_debug);
  1592. memset(osb, 0, sizeof(struct ocfs2_super));
  1593. mlog_exit_void();
  1594. }
  1595. /* Put OCFS2 into a readonly state, or (if the user specifies it),
  1596. * panic(). We do not support continue-on-error operation. */
  1597. static void ocfs2_handle_error(struct super_block *sb)
  1598. {
  1599. struct ocfs2_super *osb = OCFS2_SB(sb);
  1600. if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
  1601. panic("OCFS2: (device %s): panic forced after error\n",
  1602. sb->s_id);
  1603. ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
  1604. if (sb->s_flags & MS_RDONLY &&
  1605. (ocfs2_is_soft_readonly(osb) ||
  1606. ocfs2_is_hard_readonly(osb)))
  1607. return;
  1608. printk(KERN_CRIT "File system is now read-only due to the potential "
  1609. "of on-disk corruption. Please run fsck.ocfs2 once the file "
  1610. "system is unmounted.\n");
  1611. sb->s_flags |= MS_RDONLY;
  1612. ocfs2_set_ro_flag(osb, 0);
  1613. }
  1614. static char error_buf[1024];
  1615. void __ocfs2_error(struct super_block *sb,
  1616. const char *function,
  1617. const char *fmt, ...)
  1618. {
  1619. va_list args;
  1620. va_start(args, fmt);
  1621. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1622. va_end(args);
  1623. /* Not using mlog here because we want to show the actual
  1624. * function the error came from. */
  1625. printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
  1626. sb->s_id, function, error_buf);
  1627. ocfs2_handle_error(sb);
  1628. }
  1629. /* Handle critical errors. This is intentionally more drastic than
  1630. * ocfs2_handle_error, so we only use for things like journal errors,
  1631. * etc. */
  1632. void __ocfs2_abort(struct super_block* sb,
  1633. const char *function,
  1634. const char *fmt, ...)
  1635. {
  1636. va_list args;
  1637. va_start(args, fmt);
  1638. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1639. va_end(args);
  1640. printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
  1641. sb->s_id, function, error_buf);
  1642. /* We don't have the cluster support yet to go straight to
  1643. * hard readonly in here. Until then, we want to keep
  1644. * ocfs2_abort() so that we can at least mark critical
  1645. * errors.
  1646. *
  1647. * TODO: This should abort the journal and alert other nodes
  1648. * that our slot needs recovery. */
  1649. /* Force a panic(). This stinks, but it's better than letting
  1650. * things continue without having a proper hard readonly
  1651. * here. */
  1652. OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  1653. ocfs2_handle_error(sb);
  1654. }
  1655. module_init(ocfs2_init);
  1656. module_exit(ocfs2_exit);