query.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <time.h>
#include <libgen.h>
#include <fuse/fuse.h>
#include "mysqlfs.h"
#include "query.h"
#include "log.h"

Include dependency graph for query.c:

Go to the source code of this file.

Defines

#define SQL_MAX   10240
#define INODE_CACHE_MAX   4096

Functions

int query_getattr (MYSQL *mysql, const char *path, struct stat *stbuf)
 Get the attributes of an inode, filling in a struct stat.
int query_inode_full (MYSQL *mysql, const char *path, char *name, size_t name_len, long *inode, long *parent, long *nlinks)
 Walk the directory tree to find the inode at the given absolute path, storing name, inode, parent inode, and number of links.
long query_inode (MYSQL *mysql, const char *path)
 Get the inode of a pathname.
int query_truncate (MYSQL *mysql, const char *path, off_t length)
 Change the length of a file, truncating any additional data blocks and immediately deleting the data blocks past the truncation length.
int query_mkdirentry (MYSQL *mysql, long inode, const char *name, long parent)
 The opposite of query_rmdirentry(), this function creates a directory in the tree with given inode and parent inode.
int query_rmdirentry (MYSQL *mysql, const char *name, long parent)
 The opposite of query_mkdirentry(), this function deletes a directory from the tree with a parent that matches the inode given.
long query_mknod (MYSQL *mysql, const char *path, mode_t mode, dev_t rdev, long parent, int alloc_data)
 Create an inode.
long query_mkdir (MYSQL *mysql, const char *path, mode_t mode, long parent)
 Create a directory.
int query_readdir (MYSQL *mysql, long inode, void *buf, fuse_fill_dir_t filler)
 Read a directory.
int query_chmod (MYSQL *mysql, long inode, mode_t mode)
 Change the mode attribute in the inode entry.
int query_chown (MYSQL *mysql, long inode, uid_t uid, gid_t gid)
 Change the uid, gid attributes in the inode entry.
int query_utime (MYSQL *mysql, long inode, struct utimbuf *time)
 Change the utime attributes atime and mtime in the inode entry.
int query_read (MYSQL *mysql, long inode, const char *buf, size_t size, off_t offset)
 Read a number of bytes (perhaps larger than BLOCK_SIZE) at an offset from a file.
int query_write (MYSQL *mysql, long inode, const char *data, size_t size, off_t offset)
 Write a number of bytes (perhaps larger than BLOCK_SIZE) at an offset into a file.
ssize_t query_size (MYSQL *mysql, long inode)
 Check the size of a file.
ssize_t query_size_block (MYSQL *mysql, long inode, unsigned long seq)
 Returns the size of the given block (inode and sequence number).
int query_rename (MYSQL *mysql, const char *from, const char *to)
 Rename a file.
int query_inuse_inc (MYSQL *mysql, long inode, int increment)
 Mark the file in-use: like a lock-manager, increment the count of users of this file so that deletions at the inode level cannot result in purged data while the file is in-use.
int query_purge_deleted (MYSQL *mysql, long inode)
 Purge inodes from files previously marked deleted (ie query_set_deleted() ) and are no longer in-use.
int query_set_deleted (MYSQL *mysql, long inode)
 Mark the inode deleted where the name of the tree column is NULL.
int query_fsck (MYSQL *mysql)
 Clean filesystem.


Define Documentation

#define INODE_CACHE_MAX   4096

Definition at line 35 of file query.c.

#define SQL_MAX   10240

Definition at line 34 of file query.c.

Referenced by query_chmod(), query_chown(), query_fsck(), query_getattr(), query_inode_full(), query_inuse_inc(), query_mkdirentry(), query_mknod(), query_purge_deleted(), query_read(), query_readdir(), query_rename(), query_rmdirentry(), query_set_deleted(), query_size(), query_size_block(), query_truncate(), and query_utime().


Function Documentation

int query_chmod ( MYSQL *  mysql,
long  inode,
mode_t  mode 
)

Change the mode attribute in the inode entry.

Should be the entry-point for the kernel's implementation of a chmod() call in an inode on the FUSE filesystem.

See also:
http://linux.die.net/man/2/chmod
Returns:
0 on success; -EIO on failure (non-zero return from mysql_query() function)
Parameters:
mysql handle to connection to the database
inode inode to update
mode new mode to set into the inode

Definition at line 521 of file query.c.

References LOG_D_SQL, LOG_ERROR, log_printf(), and SQL_MAX.

Here is the call graph for this function:

int query_chown ( MYSQL *  mysql,
long  inode,
uid_t  uid,
gid_t  gid 
)

Change the uid, gid attributes in the inode entry.

Should be the entry-point for the kernel's implementation of a chown() call in an inode on the FUSE filesystem.

See also:
http://linux.die.net/man/2/chown
Returns:
0 on success; -EIO on failure (non-zero return from mysql_query() function)
Parameters:
mysql handle to connection to the database
inode inode to update
uid uid to set (-1 to make no change to uid)
gid gid to set (-1 to make no change to gid)

Definition at line 555 of file query.c.

References LOG_D_SQL, LOG_ERROR, log_printf(), and SQL_MAX.

Here is the call graph for this function:

int query_fsck ( MYSQL *  mysql  ) 

Clean filesystem.

Only run in pool_check_mysql_setup() if mysqlfs_opt::fsck == 1

  1. delete inodes with deleted==1
  2. delete direntries without corresponding inode
  3. set inuse=0 for all inodes
  4. delete data without existing inode
  5. synchronize inodes.size=data.LENGTH(data)
  6. optimize tables

Returns:
return from call to mysql_query()
Parameters:
mysql handle to database connection

Definition at line 1209 of file query.c.

References LOG_D_SQL, log_printf(), and SQL_MAX.

Here is the call graph for this function:

int query_getattr ( MYSQL *  mysql,
const char *  path,
struct stat *  stbuf 
)

Get the attributes of an inode, filling in a struct stat.

This function uses query_inode_full() to get the inode and nlinks of the given path, then reads the inode data from the database, storing this data into the provided structure.

Returns:
0 if successful

-EIO if the result of mysql_query() is non-zero

-ENOENT if the inode at the give path is not found (actually, if the number of results is not exactly 1)

Parameters:
mysql handle to connection to the database
path pathname to check
stbuf struct stat to fill with the inode contents

Definition at line 79 of file query.c.

References LOG_D_SQL, LOG_ERROR, log_printf(), query_inode_full(), and SQL_MAX.

Here is the call graph for this function:

long query_inode ( MYSQL *  mysql,
const char *  path 
)

Get the inode of a pathname.

This is really a convenience function wrapping the query_inode_full() function, but can instead be used as a function with a nestable return value.

Returns:
ID of inode

< 0 result of query_inode_full() if that ufnction reports a failure

Parameters:
mysql handle to connection to the database
path (full) pathname of inode to find

Definition at line 245 of file query.c.

References query_inode_full().

Referenced by query_rename(), and query_truncate().

Here is the call graph for this function:

int query_inode_full ( MYSQL *  mysql,
const char *  path,
char *  name,
size_t  name_len,
long *  inode,
long *  parent,
long *  nlinks 
)

Walk the directory tree to find the inode at the given absolute path, storing name, inode, parent inode, and number of links.

Last developer of this function indicates that the pathname may overflow -- sounds like a good testcase :)

If any of the name, inode, parent, or nlinks are given, those values will be recorded form the inode data to the given buffers. The name is written to the given name_len.

Returns:
0 if successful

-EIO if the result of mysql_query() is non-zero

-ENOENT if the file at this path is not found

Parameters:
mysql handle to connection to the database
path (absolute) pathname of inode to find
name destination to record (relative) name of the inode (may be NULL)
name_len length of destination buffer "name"
inode where to write the inode value, if found (may be NULL)
parent where to write the parent's inode value, if found (may be NULL)
nlinks where to write the number of links to the inode, if found (may be NULL)

Definition at line 154 of file query.c.

References LOG_D_OTHER, LOG_D_SQL, LOG_ERROR, log_printf(), PATH_MAX, and SQL_MAX.

Referenced by query_getattr(), and query_inode().

Here is the call graph for this function:

int query_inuse_inc ( MYSQL *  mysql,
long  inode,
int  increment 
)

Mark the file in-use: like a lock-manager, increment the count of users of this file so that deletions at the inode level cannot result in purged data while the file is in-use.

Returns:
0 on success; -EIO if the mysql_query() is non-zero (and the error is logged)
Parameters:
mysql handle to the database
inode inode of the file that is to be marked deleted
increment how many additional "uses" to increment in the file's inode

Definition at line 1114 of file query.c.

References LOG_D_SQL, log_printf(), and SQL_MAX.

Here is the call graph for this function:

long query_mkdir ( MYSQL *  mysql,
const char *  path,
mode_t  mode,
long  parent 
)

Create a directory.

This is really a wrapper to a specific invocation of query_mknod().

See also:
http://linux.die.net/man/2/mkdir
Returns:
ID of new inode, or -ENOENT if the path contains no parent directory "/"
Parameters:
mysql handle to connection to the database
path name of directory to create
mode access mode of new directory
parent inode of directory holding files (parent inode)

Definition at line 456 of file query.c.

References query_mknod().

Here is the call graph for this function:

int query_mkdirentry ( MYSQL *  mysql,
long  inode,
const char *  name,
long  parent 
)

The opposite of query_rmdirentry(), this function creates a directory in the tree with given inode and parent inode.

Returns:
0 if successful

-EIO if the result of mysql_query() is non-zero

Parameters:
mysql handle to connection to the database
inode inode of new directory
name name (relative) of directory to create
parent inode of directory holding the directory

Definition at line 323 of file query.c.

References LOG_D_SQL, LOG_ERROR, log_printf(), PATH_MAX, and SQL_MAX.

Here is the call graph for this function:

long query_mknod ( MYSQL *  mysql,
const char *  path,
mode_t  mode,
dev_t  rdev,
long  parent,
int  alloc_data 
)

Create an inode.

This function creates a child entry of the specified dev_t type and mode in the "parent" directory given as the "parent". Any parent directory information (ie "dirname(path)") is stripped out, leaving only the base pathname, but it has to be there (perhaps a bug?) since this function wants to strip out the path information that might conflict with the parent node's pathname.

See also:
http://linux.die.net/man/2/mknod
Returns:
ID of new inode, or -ENOENT if the path contains no parent directory "/"
Parameters:
mysql handle to connection to the database
path name of directory to create
mode access mode of new directory
rdev type of inode to create
parent inode of directory holding files (parent inode)
alloc_data (unused)

Definition at line 392 of file query.c.

References LOG_D_SQL, LOG_ERROR, log_printf(), PATH_MAX, and SQL_MAX.

Referenced by query_mkdir().

Here is the call graph for this function:

int query_purge_deleted ( MYSQL *  mysql,
long  inode 
)

Purge inodes from files previously marked deleted (ie query_set_deleted() ) and are no longer in-use.

Called by mysqlfs_unlink() and mysqlfs_release()

Returns:
0 on success; -EIO if the mysql_query() is non-zero (and the error is logged)
Parameters:
mysql handle to the database
inode inode of the file that is to be marked deleted

Definition at line 1144 of file query.c.

References LOG_D_SQL, log_printf(), and SQL_MAX.

Here is the call graph for this function:

int query_read ( MYSQL *  mysql,
long  inode,
const char *  buf,
size_t  size,
off_t  offset 
)

Read a number of bytes (perhaps larger than BLOCK_SIZE) at an offset from a file.

The function does this by reading each block in succession, copying the block contents into the target buffer. The (offset % DATA_BLOCK_SIZE) issue is handled by shifting the copy slightly.

Returns:
< 0 in case of errors (propagating result of write_one_block() )

> 0 number of bytes read (should equal size parameter)

Parameters:
mysql handle to connection to the database
inode inode of the file in question
buf the buffer to copy read bytes
size number of bytes to read
offset offset within the file to read from

Definition at line 634 of file query.c.

References DATA_BLOCK_SIZE, data_blocks_info::length_first, data_blocks_info::length_last, LOG_D_SQL, LOG_ERROR, log_printf(), MIN, data_blocks_info::offset_first, data_blocks_info::seq_first, data_blocks_info::seq_last, and SQL_MAX.

Here is the call graph for this function:

int query_readdir ( MYSQL *  mysql,
long  inode,
void *  buf,
fuse_fill_dir_t  filler 
)

Read a directory.

This is done by listing the nodes with a given node as parent, calling the filler parameter (pointer-to-function) for each item. The set of results is not ordered, so results would be in the "natural order" of the database.

for the kernel's implementation of a chmod() call in an inode on the FUSE filesystem.

See also:
http://linux.die.net/man/2/readdir
Returns:
0 on success; -EIO on failure (non-zero return from mysql_query() function)
Parameters:
mysql handle to connection to the database
inode inode of directory holding files (parent inode)
buf buffer to pass to filler function
filler fuse_fill_dir_t function-pointer used to process each directory entry

Definition at line 478 of file query.c.

References LOG_ERROR, log_printf(), and SQL_MAX.

Here is the call graph for this function:

int query_rename ( MYSQL *  mysql,
const char *  from,
const char *  to 
)

Rename a file.

Called by mysqlfs_rename()

Returns:
0 on success; -EIO if the mysql_query() is non-zero (and the error is logged)
See also:
http://linux.die.net/man/2/rename
Parameters:
mysql handle to the database
from name of file before the rename
to name of file after the rename

Definition at line 1050 of file query.c.

References LOG_D_SQL, log_printf(), PATH_MAX, query_inode(), and SQL_MAX.

Here is the call graph for this function:

int query_rmdirentry ( MYSQL *  mysql,
const char *  name,
long  parent 
)

The opposite of query_mkdirentry(), this function deletes a directory from the tree with a parent that matches the inode given.

Returns:
0 if successful

-EIO if the result of mysql_query() is non-zero

Parameters:
mysql handle to connection to the database
name name (relative) of directory to delete
parent inode of directory holding the directory

Definition at line 353 of file query.c.

References LOG_D_SQL, LOG_ERROR, log_printf(), PATH_MAX, and SQL_MAX.

Here is the call graph for this function:

int query_set_deleted ( MYSQL *  mysql,
long  inode 
)

Mark the inode deleted where the name of the tree column is NULL.

This allows files that are still in use to be deleted without wiping out their underlying data.

Returns:
0 on success; -EIO if the mysql_query() is non-zero (and the error is logged)
Parameters:
mysql handle to the database
inode inode of the file that is to be marked deleted

Definition at line 1174 of file query.c.

References LOG_D_SQL, log_printf(), and SQL_MAX.

Here is the call graph for this function:

ssize_t query_size ( MYSQL *  mysql,
long  inode 
)

Check the size of a file.

Check the value by reading the attribute stored in the inode table itself. The function does not summarize the size "live" by summing the size of each data block; rather this value is updated in query_fsck(), query_truncate(), write_one_block(). This trust in the various write functions optimizes this function's response time and reduces DB load.

Returns:
total size of the file at the inode as represented in the inode block
Parameters:
mysql handle to connection to the database
inode inode of the file in question

Definition at line 940 of file query.c.

References LOG_D_SQL, log_printf(), and SQL_MAX.

Here is the call graph for this function:

ssize_t query_size_block ( MYSQL *  mysql,
long  inode,
unsigned long  seq 
)

Returns the size of the given block (inode and sequence number).

Used only by write_one_block(), which is static, so this one can/should be static?

Returns:
-ENXIO if the inode/seq pair is not found (zero rows returned, implying that block doesn't exist)

-EIO if no row is returned (implying an error in the query response, signaled by mysql_fetch_row() returning NULL)

0 if the rown is NULL (implying no result?)

1 - DATA_BLOCK_SIZE (size of the actual block)

Parameters:
mysql handle to connection to the database
inode inode of the file in question
seq sequence number of datablock to check

Definition at line 995 of file query.c.

References LOG_D_SQL, log_printf(), and SQL_MAX.

Here is the call graph for this function:

int query_truncate ( MYSQL *  mysql,
const char *  path,
off_t  length 
)

Change the length of a file, truncating any additional data blocks and immediately deleting the data blocks past the truncation length.

Function works by deleting whole blocks past the truncation point, limiting the partially-cleared block, and zeroing the extra part of the buffer. Called by mysqlfs_truncate().

See also:
http://linux.die.net/man/2/truncate
Returns:
0 on success; non-zero return of mysql_query() on error
Parameters:
mysql handle to connection to the database
path pathname of file to truncate
length new length of file

Definition at line 269 of file query.c.

References data_blocks_info::length_last, LOG_D_SQL, LOG_ERROR, log_printf(), query_inode(), data_blocks_info::seq_last, and SQL_MAX.

Here is the call graph for this function:

int query_utime ( MYSQL *  mysql,
long  inode,
struct utimbuf *  time 
)

Change the utime attributes atime and mtime in the inode entry.

Should be the entry-point for the kernel's implementation of a utime() call in an inode on the FUSE filesystem.

See also:
http://linux.die.net/man/2/utime

http://linux.die.net/man/2/stat

Returns:
0 on success; -EIO on failure (non-zero return from mysql_query() function)
Parameters:
mysql handle to connection to the database
inode inode to update the atime, mtime
time utimbuf with new actime, modtime, to set into access and modification times

Definition at line 597 of file query.c.

References LOG_D_SQL, LOG_ERROR, log_printf(), and SQL_MAX.

Here is the call graph for this function:

int query_write ( MYSQL *  mysql,
long  inode,
const char *  data,
size_t  size,
off_t  offset 
)

Write a number of bytes (perhaps larger than BLOCK_SIZE) at an offset into a file.

The function does this by writing the first partial block, then writing successive blocks until the full size is written.

Returns:
< 0 in case of errors (propagating result of write_one_block() )

> 0 number of bytes written (should equal size parameter)

Parameters:
mysql handle to connection to the database
inode inode of the file in question
data the buffer of data to write
size number of bytes to write
offset offset within the file to write to

Definition at line 879 of file query.c.

References DATA_BLOCK_SIZE, data_blocks_info::length_first, data_blocks_info::length_last, data_blocks_info::offset_first, data_blocks_info::seq_first, and data_blocks_info::seq_last.


Generated on Sun Jul 12 20:25:30 2009 for mysqlfs by  doxygen 1.4.7