super.c 47 KB

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