1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21182fca3SMike Marshall /* 31182fca3SMike Marshall * (C) 2001 Clemson University and The University of Chicago 41182fca3SMike Marshall * 51182fca3SMike Marshall * See COPYING in top-level directory. 61182fca3SMike Marshall */ 71182fca3SMike Marshall 81182fca3SMike Marshall #include "protocol.h" 9575e9461SMike Marshall #include "orangefs-kernel.h" 10575e9461SMike Marshall #include "orangefs-bufmap.h" 111182fca3SMike Marshall 121182fca3SMike Marshall #include <linux/parser.h> 13fc2e2e9cSMartin Brandenburg #include <linux/hashtable.h> 141182fca3SMike Marshall 158bb8aefdSYi Liu /* a cache for orangefs-inode objects (i.e. orangefs inode private data) */ 168bb8aefdSYi Liu static struct kmem_cache *orangefs_inode_cache; 171182fca3SMike Marshall 188bb8aefdSYi Liu /* list for storing orangefs specific superblocks in use */ 198bb8aefdSYi Liu LIST_HEAD(orangefs_superblocks); 201182fca3SMike Marshall 218bb8aefdSYi Liu DEFINE_SPINLOCK(orangefs_superblocks_lock); 221182fca3SMike Marshall 231182fca3SMike Marshall enum { 241182fca3SMike Marshall Opt_intr, 251182fca3SMike Marshall Opt_acl, 261182fca3SMike Marshall Opt_local_lock, 271182fca3SMike Marshall 281182fca3SMike Marshall Opt_err 291182fca3SMike Marshall }; 301182fca3SMike Marshall 311182fca3SMike Marshall static const match_table_t tokens = { 321182fca3SMike Marshall { Opt_acl, "acl" }, 331182fca3SMike Marshall { Opt_intr, "intr" }, 341182fca3SMike Marshall { Opt_local_lock, "local_lock" }, 351182fca3SMike Marshall { Opt_err, NULL } 361182fca3SMike Marshall }; 371182fca3SMike Marshall 38482664ddSMartin Brandenburg uint64_t orangefs_features; 391182fca3SMike Marshall 404dfdb713SDavid Howells static int orangefs_show_options(struct seq_file *m, struct dentry *root) 414dfdb713SDavid Howells { 424dfdb713SDavid Howells struct orangefs_sb_info_s *orangefs_sb = ORANGEFS_SB(root->d_sb); 434dfdb713SDavid Howells 441751e8a6SLinus Torvalds if (root->d_sb->s_flags & SB_POSIXACL) 454dfdb713SDavid Howells seq_puts(m, ",acl"); 464dfdb713SDavid Howells if (orangefs_sb->flags & ORANGEFS_OPT_INTR) 474dfdb713SDavid Howells seq_puts(m, ",intr"); 484dfdb713SDavid Howells if (orangefs_sb->flags & ORANGEFS_OPT_LOCAL_LOCK) 494dfdb713SDavid Howells seq_puts(m, ",local_lock"); 504dfdb713SDavid Howells return 0; 514dfdb713SDavid Howells } 524dfdb713SDavid Howells 531182fca3SMike Marshall static int parse_mount_options(struct super_block *sb, char *options, 541182fca3SMike Marshall int silent) 551182fca3SMike Marshall { 568bb8aefdSYi Liu struct orangefs_sb_info_s *orangefs_sb = ORANGEFS_SB(sb); 571182fca3SMike Marshall substring_t args[MAX_OPT_ARGS]; 581182fca3SMike Marshall char *p; 591182fca3SMike Marshall 601182fca3SMike Marshall /* 611182fca3SMike Marshall * Force any potential flags that might be set from the mount 621182fca3SMike Marshall * to zero, ie, initialize to unset. 631182fca3SMike Marshall */ 641751e8a6SLinus Torvalds sb->s_flags &= ~SB_POSIXACL; 658bb8aefdSYi Liu orangefs_sb->flags &= ~ORANGEFS_OPT_INTR; 668bb8aefdSYi Liu orangefs_sb->flags &= ~ORANGEFS_OPT_LOCAL_LOCK; 671182fca3SMike Marshall 681182fca3SMike Marshall while ((p = strsep(&options, ",")) != NULL) { 691182fca3SMike Marshall int token; 701182fca3SMike Marshall 711182fca3SMike Marshall if (!*p) 721182fca3SMike Marshall continue; 731182fca3SMike Marshall 741182fca3SMike Marshall token = match_token(p, tokens, args); 751182fca3SMike Marshall switch (token) { 761182fca3SMike Marshall case Opt_acl: 771751e8a6SLinus Torvalds sb->s_flags |= SB_POSIXACL; 781182fca3SMike Marshall break; 791182fca3SMike Marshall case Opt_intr: 808bb8aefdSYi Liu orangefs_sb->flags |= ORANGEFS_OPT_INTR; 811182fca3SMike Marshall break; 821182fca3SMike Marshall case Opt_local_lock: 838bb8aefdSYi Liu orangefs_sb->flags |= ORANGEFS_OPT_LOCAL_LOCK; 841182fca3SMike Marshall break; 851182fca3SMike Marshall default: 861182fca3SMike Marshall goto fail; 871182fca3SMike Marshall } 881182fca3SMike Marshall } 891182fca3SMike Marshall 901182fca3SMike Marshall return 0; 911182fca3SMike Marshall fail: 921182fca3SMike Marshall if (!silent) 931182fca3SMike Marshall gossip_err("Error: mount option [%s] is not supported.\n", p); 941182fca3SMike Marshall return -EINVAL; 951182fca3SMike Marshall } 961182fca3SMike Marshall 978bb8aefdSYi Liu static void orangefs_inode_cache_ctor(void *req) 981182fca3SMike Marshall { 998bb8aefdSYi Liu struct orangefs_inode_s *orangefs_inode = req; 1001182fca3SMike Marshall 1018bb8aefdSYi Liu inode_init_once(&orangefs_inode->vfs_inode); 1028bb8aefdSYi Liu init_rwsem(&orangefs_inode->xattr_sem); 1031182fca3SMike Marshall } 1041182fca3SMike Marshall 1058bb8aefdSYi Liu static struct inode *orangefs_alloc_inode(struct super_block *sb) 1061182fca3SMike Marshall { 1078bb8aefdSYi Liu struct orangefs_inode_s *orangefs_inode; 1081182fca3SMike Marshall 1092d4cae0dSMike Marshall orangefs_inode = kmem_cache_alloc(orangefs_inode_cache, GFP_KERNEL); 11007a25853SMarkus Elfring if (!orangefs_inode) 1111182fca3SMike Marshall return NULL; 1121182fca3SMike Marshall 1131182fca3SMike Marshall /* 1141182fca3SMike Marshall * We want to clear everything except for rw_semaphore and the 1151182fca3SMike Marshall * vfs_inode. 1161182fca3SMike Marshall */ 1178bb8aefdSYi Liu memset(&orangefs_inode->refn.khandle, 0, 16); 1188bb8aefdSYi Liu orangefs_inode->refn.fs_id = ORANGEFS_FS_ID_NULL; 1198bb8aefdSYi Liu orangefs_inode->last_failed_block_index_read = 0; 1208bb8aefdSYi Liu memset(orangefs_inode->link_target, 0, sizeof(orangefs_inode->link_target)); 1211182fca3SMike Marshall 1221182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 1238bb8aefdSYi Liu "orangefs_alloc_inode: allocated %p\n", 1248bb8aefdSYi Liu &orangefs_inode->vfs_inode); 1258bb8aefdSYi Liu return &orangefs_inode->vfs_inode; 1261182fca3SMike Marshall } 1271182fca3SMike Marshall 128f276ae0dSAl Viro static void orangefs_free_inode(struct inode *inode) 1290695d7dcSPeter Zijlstra { 1300695d7dcSPeter Zijlstra struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); 131fc2e2e9cSMartin Brandenburg struct orangefs_cached_xattr *cx; 132fc2e2e9cSMartin Brandenburg struct hlist_node *tmp; 133fc2e2e9cSMartin Brandenburg int i; 134fc2e2e9cSMartin Brandenburg 135fc2e2e9cSMartin Brandenburg hash_for_each_safe(orangefs_inode->xattr_cache, i, tmp, cx, node) { 136fc2e2e9cSMartin Brandenburg hlist_del(&cx->node); 137fc2e2e9cSMartin Brandenburg kfree(cx); 138fc2e2e9cSMartin Brandenburg } 139fc2e2e9cSMartin Brandenburg 1400695d7dcSPeter Zijlstra kmem_cache_free(orangefs_inode_cache, orangefs_inode); 1410695d7dcSPeter Zijlstra } 1420695d7dcSPeter Zijlstra 1438bb8aefdSYi Liu static void orangefs_destroy_inode(struct inode *inode) 1441182fca3SMike Marshall { 1458bb8aefdSYi Liu struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); 1461182fca3SMike Marshall 1471182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 1481182fca3SMike Marshall "%s: deallocated %p destroying inode %pU\n", 1498bb8aefdSYi Liu __func__, orangefs_inode, get_khandle_from_ino(inode)); 1501182fca3SMike Marshall } 1511182fca3SMike Marshall 152df2d7337SMartin Brandenburg static int orangefs_write_inode(struct inode *inode, 153df2d7337SMartin Brandenburg struct writeback_control *wbc) 154df2d7337SMartin Brandenburg { 155df2d7337SMartin Brandenburg gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_write_inode\n"); 156afd9fb2aSMartin Brandenburg return orangefs_inode_setattr(inode); 157df2d7337SMartin Brandenburg } 158df2d7337SMartin Brandenburg 1591182fca3SMike Marshall /* 1601182fca3SMike Marshall * NOTE: information filled in here is typically reflected in the 1611182fca3SMike Marshall * output of the system command 'df' 1621182fca3SMike Marshall */ 1638bb8aefdSYi Liu static int orangefs_statfs(struct dentry *dentry, struct kstatfs *buf) 1641182fca3SMike Marshall { 1651182fca3SMike Marshall int ret = -ENOMEM; 1668bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op = NULL; 1671182fca3SMike Marshall int flags = 0; 1681182fca3SMike Marshall struct super_block *sb = NULL; 1691182fca3SMike Marshall 1701182fca3SMike Marshall sb = dentry->d_sb; 1711182fca3SMike Marshall 1721182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 17395f5f88fSMike Marshall "%s: called on sb %p (fs_id is %d)\n", 17495f5f88fSMike Marshall __func__, 1751182fca3SMike Marshall sb, 1768bb8aefdSYi Liu (int)(ORANGEFS_SB(sb)->fs_id)); 1771182fca3SMike Marshall 1788bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_STATFS); 1791182fca3SMike Marshall if (!new_op) 1801182fca3SMike Marshall return ret; 1818bb8aefdSYi Liu new_op->upcall.req.statfs.fs_id = ORANGEFS_SB(sb)->fs_id; 1821182fca3SMike Marshall 1838bb8aefdSYi Liu if (ORANGEFS_SB(sb)->flags & ORANGEFS_OPT_INTR) 1848bb8aefdSYi Liu flags = ORANGEFS_OP_INTERRUPTIBLE; 1851182fca3SMike Marshall 1868bb8aefdSYi Liu ret = service_operation(new_op, "orangefs_statfs", flags); 1871182fca3SMike Marshall 1881182fca3SMike Marshall if (new_op->downcall.status < 0) 1891182fca3SMike Marshall goto out_op_release; 1901182fca3SMike Marshall 1911182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 192be57366eSMike Marshall "%s: got %ld blocks available | " 193be57366eSMike Marshall "%ld blocks total | %ld block size | " 194be57366eSMike Marshall "%ld files total | %ld files avail\n", 195be57366eSMike Marshall __func__, 1961182fca3SMike Marshall (long)new_op->downcall.resp.statfs.blocks_avail, 1971182fca3SMike Marshall (long)new_op->downcall.resp.statfs.blocks_total, 198be57366eSMike Marshall (long)new_op->downcall.resp.statfs.block_size, 199be57366eSMike Marshall (long)new_op->downcall.resp.statfs.files_total, 200be57366eSMike Marshall (long)new_op->downcall.resp.statfs.files_avail); 2011182fca3SMike Marshall 2021182fca3SMike Marshall buf->f_type = sb->s_magic; 2038bb8aefdSYi Liu memcpy(&buf->f_fsid, &ORANGEFS_SB(sb)->fs_id, sizeof(buf->f_fsid)); 2041182fca3SMike Marshall buf->f_bsize = new_op->downcall.resp.statfs.block_size; 20547b4948fSMartin Brandenburg buf->f_namelen = ORANGEFS_NAME_MAX; 2061182fca3SMike Marshall 2071182fca3SMike Marshall buf->f_blocks = (sector_t) new_op->downcall.resp.statfs.blocks_total; 2081182fca3SMike Marshall buf->f_bfree = (sector_t) new_op->downcall.resp.statfs.blocks_avail; 2091182fca3SMike Marshall buf->f_bavail = (sector_t) new_op->downcall.resp.statfs.blocks_avail; 2101182fca3SMike Marshall buf->f_files = (sector_t) new_op->downcall.resp.statfs.files_total; 2111182fca3SMike Marshall buf->f_ffree = (sector_t) new_op->downcall.resp.statfs.files_avail; 2120fdec1b3SMike Marshall buf->f_frsize = 0; 2131182fca3SMike Marshall 2141182fca3SMike Marshall out_op_release: 2151182fca3SMike Marshall op_release(new_op); 21695f5f88fSMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, "%s: returning %d\n", __func__, ret); 2171182fca3SMike Marshall return ret; 2181182fca3SMike Marshall } 2191182fca3SMike Marshall 2201182fca3SMike Marshall /* 2211182fca3SMike Marshall * Remount as initiated by VFS layer. We just need to reparse the mount 2221182fca3SMike Marshall * options, no need to signal pvfs2-client-core about it. 2231182fca3SMike Marshall */ 2248bb8aefdSYi Liu static int orangefs_remount_fs(struct super_block *sb, int *flags, char *data) 2251182fca3SMike Marshall { 2268bb8aefdSYi Liu gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_remount_fs: called\n"); 2271182fca3SMike Marshall return parse_mount_options(sb, data, 1); 2281182fca3SMike Marshall } 2291182fca3SMike Marshall 2301182fca3SMike Marshall /* 2311182fca3SMike Marshall * Remount as initiated by pvfs2-client-core on restart. This is used to 2321182fca3SMike Marshall * repopulate mount information left from previous pvfs2-client-core. 2331182fca3SMike Marshall * 2341182fca3SMike Marshall * the idea here is that given a valid superblock, we're 2351182fca3SMike Marshall * re-initializing the user space client with the initial mount 2361182fca3SMike Marshall * information specified when the super block was first initialized. 2371182fca3SMike Marshall * this is very different than the first initialization/creation of a 2381182fca3SMike Marshall * superblock. we use the special service_priority_operation to make 2391182fca3SMike Marshall * sure that the mount gets ahead of any other pending operation that 2401182fca3SMike Marshall * is waiting for servicing. this means that the pvfs2-client won't 2411182fca3SMike Marshall * fail to start several times for all other pending operations before 2421182fca3SMike Marshall * the client regains all of the mount information from us. 2431182fca3SMike Marshall * NOTE: this function assumes that the request_mutex is already acquired! 2441182fca3SMike Marshall */ 24545996492SAl Viro int orangefs_remount(struct orangefs_sb_info_s *orangefs_sb) 2461182fca3SMike Marshall { 2478bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 2481182fca3SMike Marshall int ret = -EINVAL; 2491182fca3SMike Marshall 2508bb8aefdSYi Liu gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_remount: called\n"); 2511182fca3SMike Marshall 2528bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_FS_MOUNT); 2531182fca3SMike Marshall if (!new_op) 2541182fca3SMike Marshall return -ENOMEM; 2558bb8aefdSYi Liu strncpy(new_op->upcall.req.fs_mount.orangefs_config_server, 25645996492SAl Viro orangefs_sb->devname, 2578bb8aefdSYi Liu ORANGEFS_MAX_SERVER_ADDR_LEN); 2581182fca3SMike Marshall 2591182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 2608bb8aefdSYi Liu "Attempting ORANGEFS Remount via host %s\n", 2618bb8aefdSYi Liu new_op->upcall.req.fs_mount.orangefs_config_server); 2621182fca3SMike Marshall 2631182fca3SMike Marshall /* 264adcf34a2SMike Marshall * we assume that the calling function has already acquired the 2651182fca3SMike Marshall * request_mutex to prevent other operations from bypassing 2661182fca3SMike Marshall * this one 2671182fca3SMike Marshall */ 2688bb8aefdSYi Liu ret = service_operation(new_op, "orangefs_remount", 269adcf34a2SMike Marshall ORANGEFS_OP_PRIORITY | ORANGEFS_OP_NO_MUTEX); 2701182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 2718bb8aefdSYi Liu "orangefs_remount: mount got return value of %d\n", 2721182fca3SMike Marshall ret); 2731182fca3SMike Marshall if (ret == 0) { 2741182fca3SMike Marshall /* 2751182fca3SMike Marshall * store the id assigned to this sb -- it's just a 2761182fca3SMike Marshall * short-lived mapping that the system interface uses 2771182fca3SMike Marshall * to map this superblock to a particular mount entry 2781182fca3SMike Marshall */ 27945996492SAl Viro orangefs_sb->id = new_op->downcall.resp.fs_mount.id; 28045996492SAl Viro orangefs_sb->mount_pending = 0; 2811182fca3SMike Marshall } 2821182fca3SMike Marshall 2831182fca3SMike Marshall op_release(new_op); 284482664ddSMartin Brandenburg 285f60fbdbfSMike Marshall if (orangefs_userspace_version >= 20906) { 286482664ddSMartin Brandenburg new_op = op_alloc(ORANGEFS_VFS_OP_FEATURES); 287482664ddSMartin Brandenburg if (!new_op) 288482664ddSMartin Brandenburg return -ENOMEM; 289482664ddSMartin Brandenburg new_op->upcall.req.features.features = 0; 290cefdc26eSMartin Brandenburg ret = service_operation(new_op, "orangefs_features", 291cefdc26eSMartin Brandenburg ORANGEFS_OP_PRIORITY | ORANGEFS_OP_NO_MUTEX); 292cefdc26eSMartin Brandenburg if (!ret) 293cefdc26eSMartin Brandenburg orangefs_features = 294cefdc26eSMartin Brandenburg new_op->downcall.resp.features.features; 295cefdc26eSMartin Brandenburg else 296cefdc26eSMartin Brandenburg orangefs_features = 0; 297482664ddSMartin Brandenburg op_release(new_op); 298482664ddSMartin Brandenburg } else { 299482664ddSMartin Brandenburg orangefs_features = 0; 300482664ddSMartin Brandenburg } 301482664ddSMartin Brandenburg 3021182fca3SMike Marshall return ret; 3031182fca3SMike Marshall } 3041182fca3SMike Marshall 3051182fca3SMike Marshall int fsid_key_table_initialize(void) 3061182fca3SMike Marshall { 3071182fca3SMike Marshall return 0; 3081182fca3SMike Marshall } 3091182fca3SMike Marshall 3101182fca3SMike Marshall void fsid_key_table_finalize(void) 3111182fca3SMike Marshall { 3121182fca3SMike Marshall } 3131182fca3SMike Marshall 3148bb8aefdSYi Liu static const struct super_operations orangefs_s_ops = { 3158bb8aefdSYi Liu .alloc_inode = orangefs_alloc_inode, 316f276ae0dSAl Viro .free_inode = orangefs_free_inode, 3178bb8aefdSYi Liu .destroy_inode = orangefs_destroy_inode, 318df2d7337SMartin Brandenburg .write_inode = orangefs_write_inode, 3191182fca3SMike Marshall .drop_inode = generic_delete_inode, 3208bb8aefdSYi Liu .statfs = orangefs_statfs, 3218bb8aefdSYi Liu .remount_fs = orangefs_remount_fs, 3224dfdb713SDavid Howells .show_options = orangefs_show_options, 3231182fca3SMike Marshall }; 3241182fca3SMike Marshall 3258bb8aefdSYi Liu static struct dentry *orangefs_fh_to_dentry(struct super_block *sb, 3261182fca3SMike Marshall struct fid *fid, 3271182fca3SMike Marshall int fh_len, 3281182fca3SMike Marshall int fh_type) 3291182fca3SMike Marshall { 3308bb8aefdSYi Liu struct orangefs_object_kref refn; 3311182fca3SMike Marshall 3321182fca3SMike Marshall if (fh_len < 5 || fh_type > 2) 3331182fca3SMike Marshall return NULL; 3341182fca3SMike Marshall 3358bb8aefdSYi Liu ORANGEFS_khandle_from(&(refn.khandle), fid->raw, 16); 3361182fca3SMike Marshall refn.fs_id = (u32) fid->raw[4]; 3371182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 3381182fca3SMike Marshall "fh_to_dentry: handle %pU, fs_id %d\n", 3391182fca3SMike Marshall &refn.khandle, 3401182fca3SMike Marshall refn.fs_id); 3411182fca3SMike Marshall 3428bb8aefdSYi Liu return d_obtain_alias(orangefs_iget(sb, &refn)); 3431182fca3SMike Marshall } 3441182fca3SMike Marshall 3458bb8aefdSYi Liu static int orangefs_encode_fh(struct inode *inode, 3461182fca3SMike Marshall __u32 *fh, 3471182fca3SMike Marshall int *max_len, 3481182fca3SMike Marshall struct inode *parent) 3491182fca3SMike Marshall { 3501182fca3SMike Marshall int len = parent ? 10 : 5; 3511182fca3SMike Marshall int type = 1; 3528bb8aefdSYi Liu struct orangefs_object_kref refn; 3531182fca3SMike Marshall 3541182fca3SMike Marshall if (*max_len < len) { 35579d7cd61SMartin Brandenburg gossip_err("fh buffer is too small for encoding\n"); 3561182fca3SMike Marshall *max_len = len; 3571182fca3SMike Marshall type = 255; 3581182fca3SMike Marshall goto out; 3591182fca3SMike Marshall } 3601182fca3SMike Marshall 3618bb8aefdSYi Liu refn = ORANGEFS_I(inode)->refn; 3628bb8aefdSYi Liu ORANGEFS_khandle_to(&refn.khandle, fh, 16); 3631182fca3SMike Marshall fh[4] = refn.fs_id; 3641182fca3SMike Marshall 3651182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 3661182fca3SMike Marshall "Encoding fh: handle %pU, fsid %u\n", 3671182fca3SMike Marshall &refn.khandle, 3681182fca3SMike Marshall refn.fs_id); 3691182fca3SMike Marshall 3701182fca3SMike Marshall 3711182fca3SMike Marshall if (parent) { 3728bb8aefdSYi Liu refn = ORANGEFS_I(parent)->refn; 3738bb8aefdSYi Liu ORANGEFS_khandle_to(&refn.khandle, (char *) fh + 20, 16); 3741182fca3SMike Marshall fh[9] = refn.fs_id; 3751182fca3SMike Marshall 3761182fca3SMike Marshall type = 2; 3771182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 3781182fca3SMike Marshall "Encoding parent: handle %pU, fsid %u\n", 3791182fca3SMike Marshall &refn.khandle, 3801182fca3SMike Marshall refn.fs_id); 3811182fca3SMike Marshall } 3821182fca3SMike Marshall *max_len = len; 3831182fca3SMike Marshall 3841182fca3SMike Marshall out: 3851182fca3SMike Marshall return type; 3861182fca3SMike Marshall } 3871182fca3SMike Marshall 388acaca36dSJulia Lawall static const struct export_operations orangefs_export_ops = { 3898bb8aefdSYi Liu .encode_fh = orangefs_encode_fh, 3908bb8aefdSYi Liu .fh_to_dentry = orangefs_fh_to_dentry, 3911182fca3SMike Marshall }; 3921182fca3SMike Marshall 3939d286b0dSMartin Brandenburg static int orangefs_unmount(int id, __s32 fs_id, const char *devname) 3949d286b0dSMartin Brandenburg { 3959d286b0dSMartin Brandenburg struct orangefs_kernel_op_s *op; 3969d286b0dSMartin Brandenburg int r; 3979d286b0dSMartin Brandenburg op = op_alloc(ORANGEFS_VFS_OP_FS_UMOUNT); 3989d286b0dSMartin Brandenburg if (!op) 3999d286b0dSMartin Brandenburg return -ENOMEM; 4009d286b0dSMartin Brandenburg op->upcall.req.fs_umount.id = id; 4019d286b0dSMartin Brandenburg op->upcall.req.fs_umount.fs_id = fs_id; 4029d286b0dSMartin Brandenburg strncpy(op->upcall.req.fs_umount.orangefs_config_server, 4036bdfb48dSXiongfeng Wang devname, ORANGEFS_MAX_SERVER_ADDR_LEN - 1); 4049d286b0dSMartin Brandenburg r = service_operation(op, "orangefs_fs_umount", 0); 4059d286b0dSMartin Brandenburg /* Not much to do about an error here. */ 4069d286b0dSMartin Brandenburg if (r) 4079d286b0dSMartin Brandenburg gossip_err("orangefs_unmount: service_operation %d\n", r); 4089d286b0dSMartin Brandenburg op_release(op); 4099d286b0dSMartin Brandenburg return r; 4109d286b0dSMartin Brandenburg } 4119d286b0dSMartin Brandenburg 4128bb8aefdSYi Liu static int orangefs_fill_sb(struct super_block *sb, 4138bb8aefdSYi Liu struct orangefs_fs_mount_response *fs_mount, 4145c0dbbc6SAl Viro void *data, int silent) 4151182fca3SMike Marshall { 416f2d34c73SMartin Brandenburg int ret; 417f2d34c73SMartin Brandenburg struct inode *root; 418f2d34c73SMartin Brandenburg struct dentry *root_dentry; 4198bb8aefdSYi Liu struct orangefs_object_kref root_object; 4201182fca3SMike Marshall 4218bb8aefdSYi Liu ORANGEFS_SB(sb)->sb = sb; 4221182fca3SMike Marshall 4238bb8aefdSYi Liu ORANGEFS_SB(sb)->root_khandle = fs_mount->root_khandle; 4248bb8aefdSYi Liu ORANGEFS_SB(sb)->fs_id = fs_mount->fs_id; 4258bb8aefdSYi Liu ORANGEFS_SB(sb)->id = fs_mount->id; 4261182fca3SMike Marshall 4275c0dbbc6SAl Viro if (data) { 4285c0dbbc6SAl Viro ret = parse_mount_options(sb, data, silent); 4291182fca3SMike Marshall if (ret) 4301182fca3SMike Marshall return ret; 4311182fca3SMike Marshall } 4321182fca3SMike Marshall 4331182fca3SMike Marshall /* Hang the xattr handlers off the superblock */ 4348bb8aefdSYi Liu sb->s_xattr = orangefs_xattr_handlers; 4358bb8aefdSYi Liu sb->s_magic = ORANGEFS_SUPER_MAGIC; 4368bb8aefdSYi Liu sb->s_op = &orangefs_s_ops; 4378bb8aefdSYi Liu sb->s_d_op = &orangefs_dentry_operations; 4381182fca3SMike Marshall 4399f8fd53cSMartin Brandenburg sb->s_blocksize = PAGE_SIZE; 4409f8fd53cSMartin Brandenburg sb->s_blocksize_bits = PAGE_SHIFT; 4411182fca3SMike Marshall sb->s_maxbytes = MAX_LFS_FILESIZE; 4421182fca3SMike Marshall 443f2d34c73SMartin Brandenburg ret = super_setup_bdi(sb); 444f2d34c73SMartin Brandenburg if (ret) 445f2d34c73SMartin Brandenburg return ret; 446f2d34c73SMartin Brandenburg 4478bb8aefdSYi Liu root_object.khandle = ORANGEFS_SB(sb)->root_khandle; 4488bb8aefdSYi Liu root_object.fs_id = ORANGEFS_SB(sb)->fs_id; 4491182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 4501182fca3SMike Marshall "get inode %pU, fsid %d\n", 4511182fca3SMike Marshall &root_object.khandle, 4521182fca3SMike Marshall root_object.fs_id); 4531182fca3SMike Marshall 4548bb8aefdSYi Liu root = orangefs_iget(sb, &root_object); 4551182fca3SMike Marshall if (IS_ERR(root)) 4561182fca3SMike Marshall return PTR_ERR(root); 4571182fca3SMike Marshall 4581182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 4591182fca3SMike Marshall "Allocated root inode [%p] with mode %x\n", 4601182fca3SMike Marshall root, 4611182fca3SMike Marshall root->i_mode); 4621182fca3SMike Marshall 4631182fca3SMike Marshall /* allocates and places root dentry in dcache */ 4641182fca3SMike Marshall root_dentry = d_make_root(root); 465b05a7851SAl Viro if (!root_dentry) 4661182fca3SMike Marshall return -ENOMEM; 4671182fca3SMike Marshall 4688bb8aefdSYi Liu sb->s_export_op = &orangefs_export_ops; 4691182fca3SMike Marshall sb->s_root = root_dentry; 4701182fca3SMike Marshall return 0; 4711182fca3SMike Marshall } 4721182fca3SMike Marshall 4738bb8aefdSYi Liu struct dentry *orangefs_mount(struct file_system_type *fst, 4741182fca3SMike Marshall int flags, 4751182fca3SMike Marshall const char *devname, 4761182fca3SMike Marshall void *data) 4771182fca3SMike Marshall { 478*507874c0SColin Ian King int ret; 4791182fca3SMike Marshall struct super_block *sb = ERR_PTR(-EINVAL); 4808bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 4811be21f86SMike Marshall struct dentry *d = ERR_PTR(-EINVAL); 4821182fca3SMike Marshall 4831182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 4848bb8aefdSYi Liu "orangefs_mount: called with devname %s\n", 4851182fca3SMike Marshall devname); 4861182fca3SMike Marshall 4871182fca3SMike Marshall if (!devname) { 4881182fca3SMike Marshall gossip_err("ERROR: device name not specified.\n"); 4891182fca3SMike Marshall return ERR_PTR(-EINVAL); 4901182fca3SMike Marshall } 4911182fca3SMike Marshall 4928bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_FS_MOUNT); 4931182fca3SMike Marshall if (!new_op) 4941182fca3SMike Marshall return ERR_PTR(-ENOMEM); 4951182fca3SMike Marshall 4968bb8aefdSYi Liu strncpy(new_op->upcall.req.fs_mount.orangefs_config_server, 4971182fca3SMike Marshall devname, 4986bdfb48dSXiongfeng Wang ORANGEFS_MAX_SERVER_ADDR_LEN - 1); 4991182fca3SMike Marshall 5001182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 5018bb8aefdSYi Liu "Attempting ORANGEFS Mount via host %s\n", 5028bb8aefdSYi Liu new_op->upcall.req.fs_mount.orangefs_config_server); 5031182fca3SMike Marshall 5048bb8aefdSYi Liu ret = service_operation(new_op, "orangefs_mount", 0); 5051182fca3SMike Marshall gossip_debug(GOSSIP_SUPER_DEBUG, 5068bb8aefdSYi Liu "orangefs_mount: mount got return value of %d\n", ret); 5071182fca3SMike Marshall if (ret) 5081182fca3SMike Marshall goto free_op; 5091182fca3SMike Marshall 5108bb8aefdSYi Liu if (new_op->downcall.resp.fs_mount.fs_id == ORANGEFS_FS_ID_NULL) { 5111182fca3SMike Marshall gossip_err("ERROR: Retrieved null fs_id\n"); 5121182fca3SMike Marshall ret = -EINVAL; 5131182fca3SMike Marshall goto free_op; 5141182fca3SMike Marshall } 5151182fca3SMike Marshall 5161be21f86SMike Marshall sb = sget(fst, NULL, set_anon_super, flags, NULL); 5171be21f86SMike Marshall 5181be21f86SMike Marshall if (IS_ERR(sb)) { 5191be21f86SMike Marshall d = ERR_CAST(sb); 5209d286b0dSMartin Brandenburg orangefs_unmount(new_op->downcall.resp.fs_mount.id, 5219d286b0dSMartin Brandenburg new_op->downcall.resp.fs_mount.fs_id, devname); 5221182fca3SMike Marshall goto free_op; 5231182fca3SMike Marshall } 5241182fca3SMike Marshall 525f2d34c73SMartin Brandenburg /* alloc and init our private orangefs sb info */ 526f2d34c73SMartin Brandenburg sb->s_fs_info = kzalloc(sizeof(struct orangefs_sb_info_s), GFP_KERNEL); 527f2d34c73SMartin Brandenburg if (!ORANGEFS_SB(sb)) { 528f2d34c73SMartin Brandenburg d = ERR_PTR(-ENOMEM); 529f2d34c73SMartin Brandenburg goto free_op; 530f2d34c73SMartin Brandenburg } 531f2d34c73SMartin Brandenburg 5328bb8aefdSYi Liu ret = orangefs_fill_sb(sb, 5335c0dbbc6SAl Viro &new_op->downcall.resp.fs_mount, data, 5341751e8a6SLinus Torvalds flags & SB_SILENT ? 1 : 0); 5351be21f86SMike Marshall 5361be21f86SMike Marshall if (ret) { 5371be21f86SMike Marshall d = ERR_PTR(ret); 5381ec1688cSMartin Brandenburg goto free_sb_and_op; 5391be21f86SMike Marshall } 5401182fca3SMike Marshall 5411182fca3SMike Marshall /* 5421182fca3SMike Marshall * on successful mount, store the devname and data 5431182fca3SMike Marshall * used 5441182fca3SMike Marshall */ 5458bb8aefdSYi Liu strncpy(ORANGEFS_SB(sb)->devname, 5461182fca3SMike Marshall devname, 5476bdfb48dSXiongfeng Wang ORANGEFS_MAX_SERVER_ADDR_LEN - 1); 5481182fca3SMike Marshall 5491182fca3SMike Marshall /* mount_pending must be cleared */ 5508bb8aefdSYi Liu ORANGEFS_SB(sb)->mount_pending = 0; 5511182fca3SMike Marshall 5521182fca3SMike Marshall /* 5538bb8aefdSYi Liu * finally, add this sb to our list of known orangefs 5541182fca3SMike Marshall * sb's 5551182fca3SMike Marshall */ 55645996492SAl Viro gossip_debug(GOSSIP_SUPER_DEBUG, 55745996492SAl Viro "Adding SB %p to orangefs superblocks\n", 55845996492SAl Viro ORANGEFS_SB(sb)); 55945996492SAl Viro spin_lock(&orangefs_superblocks_lock); 56045996492SAl Viro list_add_tail(&ORANGEFS_SB(sb)->list, &orangefs_superblocks); 56145996492SAl Viro spin_unlock(&orangefs_superblocks_lock); 5621182fca3SMike Marshall op_release(new_op); 563482664ddSMartin Brandenburg 5641ec1688cSMartin Brandenburg /* Must be removed from the list now. */ 5651ec1688cSMartin Brandenburg ORANGEFS_SB(sb)->no_list = 0; 5661ec1688cSMartin Brandenburg 567f60fbdbfSMike Marshall if (orangefs_userspace_version >= 20906) { 568482664ddSMartin Brandenburg new_op = op_alloc(ORANGEFS_VFS_OP_FEATURES); 569482664ddSMartin Brandenburg if (!new_op) 570482664ddSMartin Brandenburg return ERR_PTR(-ENOMEM); 571482664ddSMartin Brandenburg new_op->upcall.req.features.features = 0; 572482664ddSMartin Brandenburg ret = service_operation(new_op, "orangefs_features", 0); 573482664ddSMartin Brandenburg orangefs_features = new_op->downcall.resp.features.features; 574482664ddSMartin Brandenburg op_release(new_op); 575482664ddSMartin Brandenburg } else { 576482664ddSMartin Brandenburg orangefs_features = 0; 577482664ddSMartin Brandenburg } 578482664ddSMartin Brandenburg 5791be21f86SMike Marshall return dget(sb->s_root); 5801182fca3SMike Marshall 5811ec1688cSMartin Brandenburg free_sb_and_op: 5821ec1688cSMartin Brandenburg /* Will call orangefs_kill_sb with sb not in list. */ 5831ec1688cSMartin Brandenburg ORANGEFS_SB(sb)->no_list = 1; 5849d286b0dSMartin Brandenburg /* ORANGEFS_VFS_OP_FS_UMOUNT is done by orangefs_kill_sb. */ 5851ec1688cSMartin Brandenburg deactivate_locked_super(sb); 5861182fca3SMike Marshall free_op: 5878bb8aefdSYi Liu gossip_err("orangefs_mount: mount request failed with %d\n", ret); 5881182fca3SMike Marshall if (ret == -EINVAL) { 5898bb8aefdSYi Liu gossip_err("Ensure that all orangefs-servers have the same FS configuration files\n"); 5901182fca3SMike Marshall gossip_err("Look at pvfs2-client-core log file (typically /tmp/pvfs2-client.log) for more details\n"); 5911182fca3SMike Marshall } 5921182fca3SMike Marshall 5931182fca3SMike Marshall op_release(new_op); 5941182fca3SMike Marshall 5951be21f86SMike Marshall return d; 5961182fca3SMike Marshall } 5971182fca3SMike Marshall 5988bb8aefdSYi Liu void orangefs_kill_sb(struct super_block *sb) 5991182fca3SMike Marshall { 6009d286b0dSMartin Brandenburg int r; 6018bb8aefdSYi Liu gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_kill_sb: called\n"); 6021182fca3SMike Marshall 603524b1d30SAl Viro /* provided sb cleanup */ 604524b1d30SAl Viro kill_anon_super(sb); 605524b1d30SAl Viro 60665903842SAl Viro if (!ORANGEFS_SB(sb)) { 60765903842SAl Viro mutex_lock(&orangefs_request_mutex); 60865903842SAl Viro mutex_unlock(&orangefs_request_mutex); 60965903842SAl Viro return; 61065903842SAl Viro } 6111182fca3SMike Marshall /* 6121182fca3SMike Marshall * issue the unmount to userspace to tell it to remove the 6131182fca3SMike Marshall * dynamic mount info it has for this superblock 6141182fca3SMike Marshall */ 6159d286b0dSMartin Brandenburg r = orangefs_unmount(ORANGEFS_SB(sb)->id, ORANGEFS_SB(sb)->fs_id, 6169d286b0dSMartin Brandenburg ORANGEFS_SB(sb)->devname); 6179d286b0dSMartin Brandenburg if (!r) 6189d286b0dSMartin Brandenburg ORANGEFS_SB(sb)->mount_pending = 1; 6191182fca3SMike Marshall 6201ec1688cSMartin Brandenburg if (!ORANGEFS_SB(sb)->no_list) { 6218bb8aefdSYi Liu /* remove the sb from our list of orangefs specific sb's */ 62245996492SAl Viro spin_lock(&orangefs_superblocks_lock); 6231ec1688cSMartin Brandenburg /* not list_del_init */ 6241ec1688cSMartin Brandenburg __list_del_entry(&ORANGEFS_SB(sb)->list); 62545996492SAl Viro ORANGEFS_SB(sb)->list.prev = NULL; 62645996492SAl Viro spin_unlock(&orangefs_superblocks_lock); 6271ec1688cSMartin Brandenburg } 62845996492SAl Viro 62945996492SAl Viro /* 63045996492SAl Viro * make sure that ORANGEFS_DEV_REMOUNT_ALL loop that might've seen us 63145996492SAl Viro * gets completed before we free the dang thing. 63245996492SAl Viro */ 6331d503617SMartin Brandenburg mutex_lock(&orangefs_request_mutex); 6341d503617SMartin Brandenburg mutex_unlock(&orangefs_request_mutex); 6351182fca3SMike Marshall 6368bb8aefdSYi Liu /* free the orangefs superblock private data */ 6378bb8aefdSYi Liu kfree(ORANGEFS_SB(sb)); 6381182fca3SMike Marshall } 6391182fca3SMike Marshall 6408bb8aefdSYi Liu int orangefs_inode_cache_initialize(void) 6411182fca3SMike Marshall { 6426b330623SDavid Windsor orangefs_inode_cache = kmem_cache_create_usercopy( 6436b330623SDavid Windsor "orangefs_inode_cache", 6448bb8aefdSYi Liu sizeof(struct orangefs_inode_s), 6451182fca3SMike Marshall 0, 6468bb8aefdSYi Liu ORANGEFS_CACHE_CREATE_FLAGS, 6476b330623SDavid Windsor offsetof(struct orangefs_inode_s, 6486b330623SDavid Windsor link_target), 6496b330623SDavid Windsor sizeof_field(struct orangefs_inode_s, 6506b330623SDavid Windsor link_target), 6518bb8aefdSYi Liu orangefs_inode_cache_ctor); 6521182fca3SMike Marshall 6538bb8aefdSYi Liu if (!orangefs_inode_cache) { 6548bb8aefdSYi Liu gossip_err("Cannot create orangefs_inode_cache\n"); 6551182fca3SMike Marshall return -ENOMEM; 6561182fca3SMike Marshall } 6571182fca3SMike Marshall return 0; 6581182fca3SMike Marshall } 6591182fca3SMike Marshall 6608bb8aefdSYi Liu int orangefs_inode_cache_finalize(void) 6611182fca3SMike Marshall { 6628bb8aefdSYi Liu kmem_cache_destroy(orangefs_inode_cache); 6631182fca3SMike Marshall return 0; 6641182fca3SMike Marshall } 665