super.c 56 KB

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