super.c 63 KB

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