super.c 69 KB

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