super.c 64 KB

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