super.c 62 KB

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