super.c 50 KB

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