super.c 65 KB

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