blob: b699aac268a6c3c172e3507dff9d17005f79ed2f [file] [log] [blame]
Dan Williams7b6be842017-04-11 09:49:49 -07001/*
2 * Copyright(c) 2017 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13#include <linux/pagemap.h>
14#include <linux/module.h>
15#include <linux/mount.h>
16#include <linux/magic.h>
Dan Williamsef510422017-05-08 10:55:27 -070017#include <linux/genhd.h>
Dan Williams7b6be842017-04-11 09:49:49 -070018#include <linux/cdev.h>
19#include <linux/hash.h>
20#include <linux/slab.h>
Dan Williams7e026c82017-05-29 12:57:56 -070021#include <linux/uio.h>
Dan Williams6568b082017-01-24 18:44:18 -080022#include <linux/dax.h>
Dan Williams7b6be842017-04-11 09:49:49 -070023#include <linux/fs.h>
24
Dan Williams7b6be842017-04-11 09:49:49 -070025static dev_t dax_devt;
26DEFINE_STATIC_SRCU(dax_srcu);
27static struct vfsmount *dax_mnt;
28static DEFINE_IDA(dax_minor_ida);
29static struct kmem_cache *dax_cache __read_mostly;
30static struct super_block *dax_superblock __read_mostly;
31
Dan Williams72058002017-04-19 15:14:31 -070032#define DAX_HASH_SIZE (PAGE_SIZE / sizeof(struct hlist_head))
33static struct hlist_head dax_host_list[DAX_HASH_SIZE];
34static DEFINE_SPINLOCK(dax_host_lock);
35
Dan Williams7b6be842017-04-11 09:49:49 -070036int dax_read_lock(void)
37{
38 return srcu_read_lock(&dax_srcu);
39}
40EXPORT_SYMBOL_GPL(dax_read_lock);
41
42void dax_read_unlock(int id)
43{
44 srcu_read_unlock(&dax_srcu, id);
45}
46EXPORT_SYMBOL_GPL(dax_read_unlock);
47
Dan Williams9d109082017-05-13 16:18:21 -070048#ifdef CONFIG_BLOCK
Dan Williams78f35472017-08-30 09:16:38 -070049#include <linux/blkdev.h>
50
Dan Williamsef510422017-05-08 10:55:27 -070051int bdev_dax_pgoff(struct block_device *bdev, sector_t sector, size_t size,
52 pgoff_t *pgoff)
53{
54 phys_addr_t phys_off = (get_start_sect(bdev) + sector) * 512;
55
56 if (pgoff)
57 *pgoff = PHYS_PFN(phys_off);
58 if (phys_off % PAGE_SIZE || size % PAGE_SIZE)
59 return -EINVAL;
60 return 0;
61}
62EXPORT_SYMBOL(bdev_dax_pgoff);
63
Dan Williams78f35472017-08-30 09:16:38 -070064struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
65{
66 if (!blk_queue_dax(bdev->bd_queue))
67 return NULL;
68 return fs_dax_get_by_host(bdev->bd_disk->disk_name);
69}
70EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);
71
Dan Williamsef510422017-05-08 10:55:27 -070072/**
73 * __bdev_dax_supported() - Check if the device supports dax for filesystem
74 * @sb: The superblock of the device
75 * @blocksize: The block size of the device
76 *
77 * This is a library function for filesystems to check if the block device
78 * can be mounted with dax option.
79 *
80 * Return: negative errno if unsupported, 0 if supported.
81 */
82int __bdev_dax_supported(struct super_block *sb, int blocksize)
83{
84 struct block_device *bdev = sb->s_bdev;
85 struct dax_device *dax_dev;
86 pgoff_t pgoff;
87 int err, id;
88 void *kaddr;
89 pfn_t pfn;
90 long len;
91
92 if (blocksize != PAGE_SIZE) {
93 pr_err("VFS (%s): error: unsupported blocksize for dax\n",
94 sb->s_id);
95 return -EINVAL;
96 }
97
98 err = bdev_dax_pgoff(bdev, 0, PAGE_SIZE, &pgoff);
99 if (err) {
100 pr_err("VFS (%s): error: unaligned partition for dax\n",
101 sb->s_id);
102 return err;
103 }
104
105 dax_dev = dax_get_by_host(bdev->bd_disk->disk_name);
106 if (!dax_dev) {
107 pr_err("VFS (%s): error: device does not support dax\n",
108 sb->s_id);
109 return -EOPNOTSUPP;
110 }
111
112 id = dax_read_lock();
113 len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, &pfn);
114 dax_read_unlock(id);
115
116 put_dax(dax_dev);
117
118 if (len < 1) {
119 pr_err("VFS (%s): error: dax access failed (%ld)",
120 sb->s_id, len);
121 return len < 0 ? len : -EIO;
122 }
123
124 return 0;
125}
126EXPORT_SYMBOL_GPL(__bdev_dax_supported);
Dan Williams9d109082017-05-13 16:18:21 -0700127#endif
Dan Williamsef510422017-05-08 10:55:27 -0700128
Dan Williams9a60c3e2017-06-27 17:59:28 -0700129enum dax_device_flags {
130 /* !alive + rcu grace period == no new operations / mappings */
131 DAXDEV_ALIVE,
Dan Williams6e0c90d2017-06-26 21:28:41 -0700132 /* gate whether dax_flush() calls the low level flush routine */
133 DAXDEV_WRITE_CACHE,
Dan Williams9a60c3e2017-06-27 17:59:28 -0700134};
135
Dan Williams7b6be842017-04-11 09:49:49 -0700136/**
137 * struct dax_device - anchor object for dax services
138 * @inode: core vfs
139 * @cdev: optional character interface for "device dax"
Dan Williams72058002017-04-19 15:14:31 -0700140 * @host: optional name for lookups where the device path is not available
Dan Williams7b6be842017-04-11 09:49:49 -0700141 * @private: dax driver private data
Dan Williams9a60c3e2017-06-27 17:59:28 -0700142 * @flags: state and boolean properties
Dan Williams7b6be842017-04-11 09:49:49 -0700143 */
144struct dax_device {
Dan Williams72058002017-04-19 15:14:31 -0700145 struct hlist_node list;
Dan Williams7b6be842017-04-11 09:49:49 -0700146 struct inode inode;
147 struct cdev cdev;
Dan Williams72058002017-04-19 15:14:31 -0700148 const char *host;
Dan Williams7b6be842017-04-11 09:49:49 -0700149 void *private;
Dan Williams9a60c3e2017-06-27 17:59:28 -0700150 unsigned long flags;
Dan Williams6568b082017-01-24 18:44:18 -0800151 const struct dax_operations *ops;
Dan Williams7b6be842017-04-11 09:49:49 -0700152};
153
Dan Williams6e0c90d2017-06-26 21:28:41 -0700154static ssize_t write_cache_show(struct device *dev,
155 struct device_attribute *attr, char *buf)
156{
157 struct dax_device *dax_dev = dax_get_by_host(dev_name(dev));
158 ssize_t rc;
159
160 WARN_ON_ONCE(!dax_dev);
161 if (!dax_dev)
162 return -ENXIO;
163
164 rc = sprintf(buf, "%d\n", !!test_bit(DAXDEV_WRITE_CACHE,
165 &dax_dev->flags));
166 put_dax(dax_dev);
167 return rc;
168}
169
170static ssize_t write_cache_store(struct device *dev,
171 struct device_attribute *attr, const char *buf, size_t len)
172{
173 bool write_cache;
174 int rc = strtobool(buf, &write_cache);
175 struct dax_device *dax_dev = dax_get_by_host(dev_name(dev));
176
177 WARN_ON_ONCE(!dax_dev);
178 if (!dax_dev)
179 return -ENXIO;
180
181 if (rc)
182 len = rc;
183 else if (write_cache)
184 set_bit(DAXDEV_WRITE_CACHE, &dax_dev->flags);
185 else
186 clear_bit(DAXDEV_WRITE_CACHE, &dax_dev->flags);
187
188 put_dax(dax_dev);
189 return len;
190}
191static DEVICE_ATTR_RW(write_cache);
192
193static umode_t dax_visible(struct kobject *kobj, struct attribute *a, int n)
194{
195 struct device *dev = container_of(kobj, typeof(*dev), kobj);
196 struct dax_device *dax_dev = dax_get_by_host(dev_name(dev));
197
198 WARN_ON_ONCE(!dax_dev);
199 if (!dax_dev)
200 return 0;
201
202 if (a == &dev_attr_write_cache.attr && !dax_dev->ops->flush)
203 return 0;
204 return a->mode;
205}
206
207static struct attribute *dax_attributes[] = {
208 &dev_attr_write_cache.attr,
209 NULL,
210};
211
212struct attribute_group dax_attribute_group = {
213 .name = "dax",
214 .attrs = dax_attributes,
215 .is_visible = dax_visible,
216};
217EXPORT_SYMBOL_GPL(dax_attribute_group);
218
Dan Williamsb0686262017-01-26 20:37:35 -0800219/**
220 * dax_direct_access() - translate a device pgoff to an absolute pfn
221 * @dax_dev: a dax_device instance representing the logical memory range
222 * @pgoff: offset in pages from the start of the device to translate
223 * @nr_pages: number of consecutive pages caller can handle relative to @pfn
224 * @kaddr: output parameter that returns a virtual address mapping of pfn
225 * @pfn: output parameter that returns an absolute pfn translation of @pgoff
226 *
227 * Return: negative errno if an error occurs, otherwise the number of
228 * pages accessible at the device relative @pgoff.
229 */
230long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
231 void **kaddr, pfn_t *pfn)
232{
233 long avail;
234
235 /*
236 * The device driver is allowed to sleep, in order to make the
237 * memory directly accessible.
238 */
239 might_sleep();
240
241 if (!dax_dev)
242 return -EOPNOTSUPP;
243
244 if (!dax_alive(dax_dev))
245 return -ENXIO;
246
247 if (nr_pages < 0)
248 return nr_pages;
249
250 avail = dax_dev->ops->direct_access(dax_dev, pgoff, nr_pages,
251 kaddr, pfn);
252 if (!avail)
253 return -ERANGE;
254 return min(avail, nr_pages);
255}
256EXPORT_SYMBOL_GPL(dax_direct_access);
257
Dan Williams7e026c82017-05-29 12:57:56 -0700258size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
259 size_t bytes, struct iov_iter *i)
260{
261 if (!dax_alive(dax_dev))
262 return 0;
263
Dan Williams7e026c82017-05-29 12:57:56 -0700264 return dax_dev->ops->copy_from_iter(dax_dev, pgoff, addr, bytes, i);
265}
266EXPORT_SYMBOL_GPL(dax_copy_from_iter);
267
Dan Williamsabebfbe22017-05-29 13:02:52 -0700268void dax_flush(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
269 size_t size)
270{
271 if (!dax_alive(dax_dev))
272 return;
273
Dan Williams6e0c90d2017-06-26 21:28:41 -0700274 if (!test_bit(DAXDEV_WRITE_CACHE, &dax_dev->flags))
275 return;
276
Dan Williamsabebfbe22017-05-29 13:02:52 -0700277 if (dax_dev->ops->flush)
278 dax_dev->ops->flush(dax_dev, pgoff, addr, size);
279}
280EXPORT_SYMBOL_GPL(dax_flush);
281
Dan Williams6e0c90d2017-06-26 21:28:41 -0700282void dax_write_cache(struct dax_device *dax_dev, bool wc)
283{
284 if (wc)
285 set_bit(DAXDEV_WRITE_CACHE, &dax_dev->flags);
286 else
287 clear_bit(DAXDEV_WRITE_CACHE, &dax_dev->flags);
288}
289EXPORT_SYMBOL_GPL(dax_write_cache);
290
Vivek Goyal273752c2017-07-26 09:35:09 -0400291bool dax_write_cache_enabled(struct dax_device *dax_dev)
292{
293 return test_bit(DAXDEV_WRITE_CACHE, &dax_dev->flags);
294}
295EXPORT_SYMBOL_GPL(dax_write_cache_enabled);
296
Dan Williams7b6be842017-04-11 09:49:49 -0700297bool dax_alive(struct dax_device *dax_dev)
298{
299 lockdep_assert_held(&dax_srcu);
Dan Williams9a60c3e2017-06-27 17:59:28 -0700300 return test_bit(DAXDEV_ALIVE, &dax_dev->flags);
Dan Williams7b6be842017-04-11 09:49:49 -0700301}
302EXPORT_SYMBOL_GPL(dax_alive);
303
Dan Williams72058002017-04-19 15:14:31 -0700304static int dax_host_hash(const char *host)
305{
306 return hashlen_hash(hashlen_string("DAX", host)) % DAX_HASH_SIZE;
307}
308
Dan Williams7b6be842017-04-11 09:49:49 -0700309/*
310 * Note, rcu is not protecting the liveness of dax_dev, rcu is ensuring
311 * that any fault handlers or operations that might have seen
312 * dax_alive(), have completed. Any operations that start after
313 * synchronize_srcu() has run will abort upon seeing !dax_alive().
314 */
315void kill_dax(struct dax_device *dax_dev)
316{
317 if (!dax_dev)
318 return;
319
Dan Williams9a60c3e2017-06-27 17:59:28 -0700320 clear_bit(DAXDEV_ALIVE, &dax_dev->flags);
Dan Williams72058002017-04-19 15:14:31 -0700321
Dan Williams7b6be842017-04-11 09:49:49 -0700322 synchronize_srcu(&dax_srcu);
Dan Williams72058002017-04-19 15:14:31 -0700323
324 spin_lock(&dax_host_lock);
325 hlist_del_init(&dax_dev->list);
326 spin_unlock(&dax_host_lock);
327
Dan Williams7b6be842017-04-11 09:49:49 -0700328 dax_dev->private = NULL;
329}
330EXPORT_SYMBOL_GPL(kill_dax);
331
332static struct inode *dax_alloc_inode(struct super_block *sb)
333{
334 struct dax_device *dax_dev;
Dan Williamsb9d39d12017-06-09 08:50:49 -0700335 struct inode *inode;
Dan Williams7b6be842017-04-11 09:49:49 -0700336
337 dax_dev = kmem_cache_alloc(dax_cache, GFP_KERNEL);
Dan Williamsb9d39d12017-06-09 08:50:49 -0700338 inode = &dax_dev->inode;
339 inode->i_rdev = 0;
340 return inode;
Dan Williams7b6be842017-04-11 09:49:49 -0700341}
342
343static struct dax_device *to_dax_dev(struct inode *inode)
344{
345 return container_of(inode, struct dax_device, inode);
346}
347
348static void dax_i_callback(struct rcu_head *head)
349{
350 struct inode *inode = container_of(head, struct inode, i_rcu);
351 struct dax_device *dax_dev = to_dax_dev(inode);
352
Dan Williams72058002017-04-19 15:14:31 -0700353 kfree(dax_dev->host);
354 dax_dev->host = NULL;
Dan Williamsb9d39d12017-06-09 08:50:49 -0700355 if (inode->i_rdev)
356 ida_simple_remove(&dax_minor_ida, MINOR(inode->i_rdev));
Dan Williams7b6be842017-04-11 09:49:49 -0700357 kmem_cache_free(dax_cache, dax_dev);
358}
359
360static void dax_destroy_inode(struct inode *inode)
361{
362 struct dax_device *dax_dev = to_dax_dev(inode);
363
Dan Williams9a60c3e2017-06-27 17:59:28 -0700364 WARN_ONCE(test_bit(DAXDEV_ALIVE, &dax_dev->flags),
Dan Williams7b6be842017-04-11 09:49:49 -0700365 "kill_dax() must be called before final iput()\n");
366 call_rcu(&inode->i_rcu, dax_i_callback);
367}
368
369static const struct super_operations dax_sops = {
370 .statfs = simple_statfs,
371 .alloc_inode = dax_alloc_inode,
372 .destroy_inode = dax_destroy_inode,
373 .drop_inode = generic_delete_inode,
374};
375
376static struct dentry *dax_mount(struct file_system_type *fs_type,
377 int flags, const char *dev_name, void *data)
378{
379 return mount_pseudo(fs_type, "dax:", &dax_sops, NULL, DAXFS_MAGIC);
380}
381
382static struct file_system_type dax_fs_type = {
383 .name = "dax",
384 .mount = dax_mount,
385 .kill_sb = kill_anon_super,
386};
387
388static int dax_test(struct inode *inode, void *data)
389{
390 dev_t devt = *(dev_t *) data;
391
392 return inode->i_rdev == devt;
393}
394
395static int dax_set(struct inode *inode, void *data)
396{
397 dev_t devt = *(dev_t *) data;
398
399 inode->i_rdev = devt;
400 return 0;
401}
402
403static struct dax_device *dax_dev_get(dev_t devt)
404{
405 struct dax_device *dax_dev;
406 struct inode *inode;
407
408 inode = iget5_locked(dax_superblock, hash_32(devt + DAXFS_MAGIC, 31),
409 dax_test, dax_set, &devt);
410
411 if (!inode)
412 return NULL;
413
414 dax_dev = to_dax_dev(inode);
415 if (inode->i_state & I_NEW) {
Dan Williams9a60c3e2017-06-27 17:59:28 -0700416 set_bit(DAXDEV_ALIVE, &dax_dev->flags);
Dan Williams7b6be842017-04-11 09:49:49 -0700417 inode->i_cdev = &dax_dev->cdev;
418 inode->i_mode = S_IFCHR;
419 inode->i_flags = S_DAX;
420 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
421 unlock_new_inode(inode);
422 }
423
424 return dax_dev;
425}
426
Dan Williams72058002017-04-19 15:14:31 -0700427static void dax_add_host(struct dax_device *dax_dev, const char *host)
428{
429 int hash;
430
431 /*
432 * Unconditionally init dax_dev since it's coming from a
433 * non-zeroed slab cache
434 */
435 INIT_HLIST_NODE(&dax_dev->list);
436 dax_dev->host = host;
437 if (!host)
438 return;
439
440 hash = dax_host_hash(host);
441 spin_lock(&dax_host_lock);
442 hlist_add_head(&dax_dev->list, &dax_host_list[hash]);
443 spin_unlock(&dax_host_lock);
444}
445
Dan Williams6568b082017-01-24 18:44:18 -0800446struct dax_device *alloc_dax(void *private, const char *__host,
447 const struct dax_operations *ops)
Dan Williams7b6be842017-04-11 09:49:49 -0700448{
449 struct dax_device *dax_dev;
Dan Williams72058002017-04-19 15:14:31 -0700450 const char *host;
Dan Williams7b6be842017-04-11 09:49:49 -0700451 dev_t devt;
452 int minor;
453
Dan Williams72058002017-04-19 15:14:31 -0700454 host = kstrdup(__host, GFP_KERNEL);
455 if (__host && !host)
456 return NULL;
457
Dan Williamscf1e2282017-05-08 12:33:53 -0700458 minor = ida_simple_get(&dax_minor_ida, 0, MINORMASK+1, GFP_KERNEL);
Dan Williams7b6be842017-04-11 09:49:49 -0700459 if (minor < 0)
Dan Williams72058002017-04-19 15:14:31 -0700460 goto err_minor;
Dan Williams7b6be842017-04-11 09:49:49 -0700461
462 devt = MKDEV(MAJOR(dax_devt), minor);
463 dax_dev = dax_dev_get(devt);
464 if (!dax_dev)
Dan Williams72058002017-04-19 15:14:31 -0700465 goto err_dev;
Dan Williams7b6be842017-04-11 09:49:49 -0700466
Dan Williams72058002017-04-19 15:14:31 -0700467 dax_add_host(dax_dev, host);
Dan Williams6568b082017-01-24 18:44:18 -0800468 dax_dev->ops = ops;
Dan Williams7b6be842017-04-11 09:49:49 -0700469 dax_dev->private = private;
470 return dax_dev;
471
Dan Williams72058002017-04-19 15:14:31 -0700472 err_dev:
Dan Williams7b6be842017-04-11 09:49:49 -0700473 ida_simple_remove(&dax_minor_ida, minor);
Dan Williams72058002017-04-19 15:14:31 -0700474 err_minor:
475 kfree(host);
Dan Williams7b6be842017-04-11 09:49:49 -0700476 return NULL;
477}
478EXPORT_SYMBOL_GPL(alloc_dax);
479
480void put_dax(struct dax_device *dax_dev)
481{
482 if (!dax_dev)
483 return;
484 iput(&dax_dev->inode);
485}
486EXPORT_SYMBOL_GPL(put_dax);
487
488/**
Dan Williams72058002017-04-19 15:14:31 -0700489 * dax_get_by_host() - temporary lookup mechanism for filesystem-dax
490 * @host: alternate name for the device registered by a dax driver
491 */
492struct dax_device *dax_get_by_host(const char *host)
493{
494 struct dax_device *dax_dev, *found = NULL;
495 int hash, id;
496
497 if (!host)
498 return NULL;
499
500 hash = dax_host_hash(host);
501
502 id = dax_read_lock();
503 spin_lock(&dax_host_lock);
504 hlist_for_each_entry(dax_dev, &dax_host_list[hash], list) {
505 if (!dax_alive(dax_dev)
506 || strcmp(host, dax_dev->host) != 0)
507 continue;
508
509 if (igrab(&dax_dev->inode))
510 found = dax_dev;
511 break;
512 }
513 spin_unlock(&dax_host_lock);
514 dax_read_unlock(id);
515
516 return found;
517}
518EXPORT_SYMBOL_GPL(dax_get_by_host);
519
520/**
Dan Williams7b6be842017-04-11 09:49:49 -0700521 * inode_dax: convert a public inode into its dax_dev
522 * @inode: An inode with i_cdev pointing to a dax_dev
523 *
524 * Note this is not equivalent to to_dax_dev() which is for private
525 * internal use where we know the inode filesystem type == dax_fs_type.
526 */
527struct dax_device *inode_dax(struct inode *inode)
528{
529 struct cdev *cdev = inode->i_cdev;
530
531 return container_of(cdev, struct dax_device, cdev);
532}
533EXPORT_SYMBOL_GPL(inode_dax);
534
535struct inode *dax_inode(struct dax_device *dax_dev)
536{
537 return &dax_dev->inode;
538}
539EXPORT_SYMBOL_GPL(dax_inode);
540
541void *dax_get_private(struct dax_device *dax_dev)
542{
543 return dax_dev->private;
544}
545EXPORT_SYMBOL_GPL(dax_get_private);
546
547static void init_once(void *_dax_dev)
548{
549 struct dax_device *dax_dev = _dax_dev;
550 struct inode *inode = &dax_dev->inode;
551
Dan Williamsb9d39d12017-06-09 08:50:49 -0700552 memset(dax_dev, 0, sizeof(*dax_dev));
Dan Williams7b6be842017-04-11 09:49:49 -0700553 inode_init_once(inode);
554}
555
556static int __dax_fs_init(void)
557{
558 int rc;
559
560 dax_cache = kmem_cache_create("dax_cache", sizeof(struct dax_device), 0,
561 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
562 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
563 init_once);
564 if (!dax_cache)
565 return -ENOMEM;
566
567 rc = register_filesystem(&dax_fs_type);
568 if (rc)
569 goto err_register_fs;
570
571 dax_mnt = kern_mount(&dax_fs_type);
572 if (IS_ERR(dax_mnt)) {
573 rc = PTR_ERR(dax_mnt);
574 goto err_mount;
575 }
576 dax_superblock = dax_mnt->mnt_sb;
577
578 return 0;
579
580 err_mount:
581 unregister_filesystem(&dax_fs_type);
582 err_register_fs:
583 kmem_cache_destroy(dax_cache);
584
585 return rc;
586}
587
588static void __dax_fs_exit(void)
589{
590 kern_unmount(dax_mnt);
591 unregister_filesystem(&dax_fs_type);
592 kmem_cache_destroy(dax_cache);
593}
594
595static int __init dax_fs_init(void)
596{
597 int rc;
598
599 rc = __dax_fs_init();
600 if (rc)
601 return rc;
602
Dan Williamscf1e2282017-05-08 12:33:53 -0700603 rc = alloc_chrdev_region(&dax_devt, 0, MINORMASK+1, "dax");
Dan Williams7b6be842017-04-11 09:49:49 -0700604 if (rc)
605 __dax_fs_exit();
606 return rc;
607}
608
609static void __exit dax_fs_exit(void)
610{
Dan Williamscf1e2282017-05-08 12:33:53 -0700611 unregister_chrdev_region(dax_devt, MINORMASK+1);
Dan Williams7b6be842017-04-11 09:49:49 -0700612 ida_destroy(&dax_minor_ida);
613 __dax_fs_exit();
614}
615
616MODULE_AUTHOR("Intel Corporation");
617MODULE_LICENSE("GPL v2");
618subsys_initcall(dax_fs_init);
619module_exit(dax_fs_exit);