📄 super.c
字号:
ENTRY; liblustre_wait_event(0);#ifndef __CYGWIN__ LASSERT(pno->p_base->pb_ino); rc = llu_statfs(llu_i2sbi(pno->p_base->pb_ino), &fs); if (rc) RETURN(rc); /* from native driver */ buf->f_bsize = fs.f_bsize; /* file system block size */ buf->f_frsize = fs.f_bsize; /* file system fundamental block size */ buf->f_blocks = fs.f_blocks; buf->f_bfree = fs.f_bfree; buf->f_bavail = fs.f_bavail; buf->f_files = fs.f_files; /* Total number serial numbers */ buf->f_ffree = fs.f_ffree; /* Number free serial numbers */ buf->f_favail = fs.f_ffree; /* Number free ser num for non-privileged*/ buf->f_fsid = fs.f_fsid.__val[1]; buf->f_flag = 0; /* No equiv in statfs; maybe use type? */ buf->f_namemax = fs.f_namelen;#endif liblustre_wait_event(0); RETURN(0);}#endif /* _HAVE_STATVFS */static int llu_iop_mkdir_raw(struct pnode *pno, mode_t mode){ struct inode *dir = pno->p_base->pb_parent->pb_ino; struct qstr *qstr = &pno->p_base->pb_name; const char *name = qstr->name; int len = qstr->len; struct ptlrpc_request *request = NULL; struct intnl_stat *st = llu_i2stat(dir); struct mdc_op_data op_data; int err = -EMLINK; ENTRY; liblustre_wait_event(0); CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%llu/%lu(%p)\n", len, name, (long long)st->st_ino, llu_i2info(dir)->lli_st_generation, dir); if (st->st_nlink >= EXT2_LINK_MAX) RETURN(err); llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0); err = mdc_create(llu_i2sbi(dir)->ll_mdc_exp, &op_data, NULL, 0, mode | S_IFDIR, current->fsuid, current->fsgid, current->cap_effective, 0, &request); ptlrpc_req_finished(request); liblustre_wait_event(0); RETURN(err);}static int llu_iop_rmdir_raw(struct pnode *pno){ struct inode *dir = pno->p_base->pb_parent->pb_ino; struct qstr *qstr = &pno->p_base->pb_name; const char *name = qstr->name; int len = qstr->len; struct ptlrpc_request *request = NULL; struct mdc_op_data op_data; int rc; ENTRY; liblustre_wait_event(0); CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%llu/%lu(%p)\n", len, name, (long long)llu_i2stat(dir)->st_ino, llu_i2info(dir)->lli_st_generation, dir); llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, S_IFDIR); rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request); ptlrpc_req_finished(request); liblustre_wait_event(0); RETURN(rc);}#ifdef O_DIRECT#define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC|O_DIRECT)#else#define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC)#endif#define FCNTL_FLMASK_INVALID (O_NONBLOCK|O_ASYNC)/* refer to ll_file_flock() for details */int llu_file_flock(struct inode *ino, int cmd, struct file_lock *file_lock){ struct llu_inode_info *lli = llu_i2info(ino); struct intnl_stat *st = llu_i2stat(ino); struct ldlm_res_id res_id = { .name = {st->st_ino, lli->lli_st_generation, LDLM_FLOCK} }; struct ldlm_enqueue_info einfo = { LDLM_FLOCK, 0, NULL, ldlm_flock_completion_ast, NULL, file_lock }; struct lustre_handle lockh = {0}; ldlm_policy_data_t flock; int flags = 0; int rc; CDEBUG(D_VFSTRACE, "VFS Op:inode=%llu file_lock=%p\n", (unsigned long long) st->st_ino, file_lock); flock.l_flock.pid = file_lock->fl_pid; flock.l_flock.start = file_lock->fl_start; flock.l_flock.end = file_lock->fl_end; switch (file_lock->fl_type) { case F_RDLCK: einfo.ei_mode = LCK_PR; break; case F_UNLCK: einfo.ei_mode = LCK_NL; break; case F_WRLCK: einfo.ei_mode = LCK_PW; break; default: CERROR("unknown fcntl lock type: %d\n", file_lock->fl_type); LBUG(); } switch (cmd) { case F_SETLKW:#ifdef F_SETLKW64#if F_SETLKW64 != F_SETLKW case F_SETLKW64:#endif#endif flags = 0; break; case F_SETLK:#ifdef F_SETLK64#if F_SETLK64 != F_SETLK case F_SETLK64:#endif#endif flags = LDLM_FL_BLOCK_NOWAIT; break; case F_GETLK:#ifdef F_GETLK64#if F_GETLK64 != F_GETLK case F_GETLK64:#endif#endif flags = LDLM_FL_TEST_LOCK; file_lock->fl_type = einfo.ei_mode; break; default: CERROR("unknown fcntl cmd: %d\n", cmd); LBUG(); } CDEBUG(D_DLMTRACE, "inode=%llu, pid=%u, flags=%#x, mode=%u, " "start="LPU64", end="LPU64"\n", (unsigned long long) st->st_ino, flock.l_flock.pid, flags, einfo.ei_mode, flock.l_flock.start, flock.l_flock.end); rc = ldlm_cli_enqueue(llu_i2mdcexp(ino), NULL, &einfo, res_id, &flock, &flags, NULL, 0, NULL, &lockh, 0); RETURN(rc);}static int assign_type(struct file_lock *fl, int type){ switch (type) { case F_RDLCK: case F_WRLCK: case F_UNLCK: fl->fl_type = type; return 0; default: return -EINVAL; }}static int flock_to_posix_lock(struct inode *ino, struct file_lock *fl, struct flock *l){ switch (l->l_whence) { /* XXX: only SEEK_SET is supported in lustre */ case SEEK_SET: fl->fl_start = 0; break; default: return -EINVAL; } fl->fl_end = l->l_len - 1; if (l->l_len < 0) return -EINVAL; if (l->l_len == 0) fl->fl_end = OFFSET_MAX; fl->fl_pid = getpid(); fl->fl_flags = FL_POSIX; fl->fl_notify = NULL; fl->fl_insert = NULL; fl->fl_remove = NULL; /* XXX: these fields can't be filled with suitable values, but I think lustre doesn't use them. */ fl->fl_owner = NULL; fl->fl_file = NULL; return assign_type(fl, l->l_type);}static int llu_fcntl_getlk(struct inode *ino, struct flock *flock){ struct file_lock fl; int error; error = -EINVAL; if ((flock->l_type != F_RDLCK) && (flock->l_type != F_WRLCK)) goto out; error = flock_to_posix_lock(ino, &fl, flock); if (error) goto out; error = llu_file_flock(ino, F_GETLK, &fl); if (error) goto out; flock->l_type = F_UNLCK; if (fl.fl_type != F_UNLCK) { flock->l_pid = fl.fl_pid; flock->l_start = fl.fl_start; flock->l_len = fl.fl_end == OFFSET_MAX ? 0: fl.fl_end - fl.fl_start + 1; flock->l_whence = SEEK_SET; flock->l_type = fl.fl_type; }out: return error;}static int llu_fcntl_setlk(struct inode *ino, int cmd, struct flock *flock){ struct file_lock fl; int flags = llu_i2info(ino)->lli_open_flags + 1; int error; error = flock_to_posix_lock(ino, &fl, flock); if (error) goto out; if (cmd == F_SETLKW) fl.fl_flags |= FL_SLEEP; error = -EBADF; switch (flock->l_type) { case F_RDLCK: if (!(flags & FMODE_READ)) goto out; break; case F_WRLCK: if (!(flags & FMODE_WRITE)) goto out; break; case F_UNLCK: break; default: error = -EINVAL; goto out; } error = llu_file_flock(ino, cmd, &fl); if (error) goto out;out: return error;}static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn){ struct llu_inode_info *lli = llu_i2info(ino); long flags; struct flock *flock; long err = 0; liblustre_wait_event(0); switch (cmd) { case F_GETFL: *rtn = lli->lli_open_flags; break; case F_SETFL: flags = va_arg(ap, long); flags &= FCNTL_FLMASK; if (flags & FCNTL_FLMASK_INVALID) { LCONSOLE_ERROR_MSG(0x010, "liblustre does not support " "the O_NONBLOCK or O_ASYNC flags. " "Please fix your application.\n"); *rtn = -1; err = -EINVAL; break; } lli->lli_open_flags = (int)(flags & FCNTL_FLMASK) | (lli->lli_open_flags & ~FCNTL_FLMASK); *rtn = 0; break; case F_GETLK:#ifdef F_GETLK64#if F_GETLK64 != F_GETLK case F_GETLK64:#endif#endif flock = va_arg(ap, struct flock *); err = llu_fcntl_getlk(ino, flock); *rtn = err? -1: 0; break; case F_SETLK:#ifdef F_SETLKW64#if F_SETLKW64 != F_SETLKW case F_SETLKW64:#endif#endif case F_SETLKW:#ifdef F_SETLK64#if F_SETLK64 != F_SETLK case F_SETLK64:#endif#endif flock = va_arg(ap, struct flock *); err = llu_fcntl_setlk(ino, cmd, flock); *rtn = err? -1: 0; break; default: CERROR("unsupported fcntl cmd %x\n", cmd); *rtn = -1; err = -ENOSYS; break; } liblustre_wait_event(0); return err;}static int llu_get_grouplock(struct inode *inode, unsigned long arg){ struct llu_inode_info *lli = llu_i2info(inode); struct ll_file_data *fd = lli->lli_file_data; ldlm_policy_data_t policy = { .l_extent = { .start = 0, .end = OBD_OBJECT_EOF}}; struct lustre_handle lockh = { 0 }; struct lov_stripe_md *lsm = lli->lli_smd; ldlm_error_t err; int flags = 0; ENTRY; if (fd->fd_flags & LL_FILE_GROUP_LOCKED) { RETURN(-EINVAL); } policy.l_extent.gid = arg; if (lli->lli_open_flags & O_NONBLOCK) flags = LDLM_FL_BLOCK_NOWAIT; err = llu_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh, flags); if (err) RETURN(err); fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK; fd->fd_gid = arg; memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh)); RETURN(0);}static int llu_put_grouplock(struct inode *inode, unsigned long arg){ struct llu_inode_info *lli = llu_i2info(inode); struct ll_file_data *fd = lli->lli_file_data; struct lov_stripe_md *lsm = lli->lli_smd; ldlm_error_t err; ENTRY; if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED)) RETURN(-EINVAL); if (fd->fd_gid != arg) RETURN(-EINVAL); fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK); err = llu_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh); if (err)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -