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