super.c 47 KB

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