super.c 47 KB

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