super.c 66 KB

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