super.c 63 KB

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