super.c 62 KB

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