super.c 69 KB

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